@@ -26,6 +26,7 @@ import {
26
26
type CacheFunctionOptions ,
27
27
cache ,
28
28
cacheResponse ,
29
+ getResponseCacheTags ,
29
30
noCacheFetchOptions ,
30
31
parseCacheResponse ,
31
32
} from './cache' ;
@@ -370,6 +371,18 @@ interface GetRevisionOptions {
370
371
* These options don't impact the cache key and it means revisions can be shared between different fetches with different metadata options.
371
372
*/
372
373
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 [ ] ;
373
386
}
374
387
375
388
const getAPIContextId = async ( ) => {
@@ -381,9 +394,14 @@ const getAPIContextId = async () => {
381
394
* Get a revision by its ID.
382
395
*/
383
396
export 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
+ } ) ,
387
405
tagImmutable : true ,
388
406
getKeySuffix : getAPIContextId ,
389
407
get : async (
@@ -405,7 +423,13 @@ export const getRevision = cache({
405
423
}
406
424
) ;
407
425
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
+ } ) ;
409
433
} ,
410
434
getKeyArgs : ( args ) => [ args [ 0 ] , args [ 1 ] ] ,
411
435
} ) ;
@@ -414,9 +438,14 @@ export const getRevision = cache({
414
438
* Get all the pages in a revision of a space.
415
439
*/
416
440
export 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
+ } ) ,
420
449
tagImmutable : true ,
421
450
getKeySuffix : getAPIContextId ,
422
451
get : async (
@@ -440,7 +469,7 @@ export const getRevisionPages = cache({
440
469
441
470
return cacheResponse ( response , {
442
471
...( fetchOptions . metadata ? cacheTtl_7days : cacheTtl_1day ) ,
443
- data : response . data . pages ,
472
+ data : { pages : response . data . pages , tags : getResponseCacheTags ( response ) } ,
444
473
} ) ;
445
474
} ,
446
475
getKeyArgs : ( args ) => [ args [ 0 ] , args [ 1 ] ] ,
@@ -632,7 +661,7 @@ export const getRevisionFile = batch<[string, string, string], RevisionFile | nu
632
661
let files : Record < string , RevisionFile > = { } ;
633
662
634
663
if ( hasRevisionInMemory ) {
635
- const revision = await getRevision ( spaceId , revisionId , { metadata : false } ) ;
664
+ const { revision } = await getRevision ( spaceId , revisionId , { metadata : false } ) ;
636
665
files = { } ;
637
666
revision . files . forEach ( ( file ) => {
638
667
files [ file . id ] = file ;
@@ -678,7 +707,7 @@ export const getReusableContent = async (
678
707
} ) ;
679
708
680
709
if ( hasRevisionInMemory ) {
681
- const revision = await getRevision ( spaceId , revisionId , { metadata : false } ) ;
710
+ const { revision } = await getRevision ( spaceId , revisionId , { metadata : false } ) ;
682
711
return (
683
712
revision . reusableContents . find (
684
713
( reusableContent ) => reusableContent . id === reusableContentId
0 commit comments