@@ -26,6 +26,7 @@ import {
2626 type CacheFunctionOptions ,
2727 cache ,
2828 cacheResponse ,
29+ getResponseCacheTags ,
2930 noCacheFetchOptions ,
3031 parseCacheResponse ,
3132} from './cache' ;
@@ -370,6 +371,18 @@ interface GetRevisionOptions {
370371 * These options don't impact the cache key and it means revisions can be shared between different fetches with different metadata options.
371372 */
372373 metadata : boolean ;
374+
375+ /**
376+ * Whether to fetch the revision as a computed revision.
377+ * @default true
378+ */
379+ computed ?: boolean ;
380+
381+ /**
382+ * Additional tags to add to the cache entry.
383+ * It's only used for v1, once in v2 we can get rid of it.
384+ */
385+ tags ?: string [ ] ;
373386}
374387
375388const getAPIContextId = async ( ) => {
@@ -381,9 +394,14 @@ const getAPIContextId = async () => {
381394 * Get a revision by its ID.
382395 */
383396export const getRevision = cache ( {
384- name : 'api.getRevision.v2' ,
385- tag : ( spaceId , revisionId ) =>
386- getCacheTag ( { tag : 'revision' , space : spaceId , revision : revisionId } ) ,
397+ name : 'api.getRevision.v3' ,
398+ tag : ( spaceId , revisionId , fetchOptions ) =>
399+ getCacheTag ( {
400+ tag : 'revision' ,
401+ space : spaceId ,
402+ revision : revisionId ,
403+ tags : fetchOptions . tags ,
404+ } ) ,
387405 tagImmutable : true ,
388406 getKeySuffix : getAPIContextId ,
389407 get : async (
@@ -405,7 +423,13 @@ export const getRevision = cache({
405423 }
406424 ) ;
407425
408- return cacheResponse ( response , fetchOptions . metadata ? cacheTtl_7days : cacheTtl_1day ) ;
426+ return cacheResponse ( response , {
427+ ...( fetchOptions . metadata ? cacheTtl_7days : cacheTtl_1day ) ,
428+ data : {
429+ revision : response . data ,
430+ tags : getResponseCacheTags ( response ) ,
431+ } ,
432+ } ) ;
409433 } ,
410434 getKeyArgs : ( args ) => [ args [ 0 ] , args [ 1 ] ] ,
411435} ) ;
@@ -414,9 +438,14 @@ export const getRevision = cache({
414438 * Get all the pages in a revision of a space.
415439 */
416440export const getRevisionPages = cache ( {
417- name : 'api.getRevisionPages.v4' ,
418- tag : ( spaceId , revisionId ) =>
419- getCacheTag ( { tag : 'revision' , space : spaceId , revision : revisionId } ) ,
441+ name : 'api.getRevisionPages.v5' ,
442+ tag : ( spaceId , revisionId , fetchOptions ) =>
443+ getCacheTag ( {
444+ tag : 'revision' ,
445+ space : spaceId ,
446+ revision : revisionId ,
447+ tags : fetchOptions . tags ,
448+ } ) ,
420449 tagImmutable : true ,
421450 getKeySuffix : getAPIContextId ,
422451 get : async (
@@ -440,7 +469,7 @@ export const getRevisionPages = cache({
440469
441470 return cacheResponse ( response , {
442471 ...( fetchOptions . metadata ? cacheTtl_7days : cacheTtl_1day ) ,
443- data : response . data . pages ,
472+ data : { pages : response . data . pages , tags : getResponseCacheTags ( response ) } ,
444473 } ) ;
445474 } ,
446475 getKeyArgs : ( args ) => [ args [ 0 ] , args [ 1 ] ] ,
@@ -632,7 +661,7 @@ export const getRevisionFile = batch<[string, string, string], RevisionFile | nu
632661 let files : Record < string , RevisionFile > = { } ;
633662
634663 if ( hasRevisionInMemory ) {
635- const revision = await getRevision ( spaceId , revisionId , { metadata : false } ) ;
664+ const { revision } = await getRevision ( spaceId , revisionId , { metadata : false } ) ;
636665 files = { } ;
637666 revision . files . forEach ( ( file ) => {
638667 files [ file . id ] = file ;
@@ -678,7 +707,7 @@ export const getReusableContent = async (
678707 } ) ;
679708
680709 if ( hasRevisionInMemory ) {
681- const revision = await getRevision ( spaceId , revisionId , { metadata : false } ) ;
710+ const { revision } = await getRevision ( spaceId , revisionId , { metadata : false } ) ;
682711 return (
683712 revision . reusableContents . find (
684713 ( reusableContent ) => reusableContent . id === reusableContentId
0 commit comments