From 76dbf0f0d3e6abe0841785de3154739e69624fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Berg=C3=A9?= Date: Wed, 13 Mar 2024 15:32:52 +0100 Subject: [PATCH] Tag synced block in API (#256) --- src/lib/api.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lib/api.ts b/src/lib/api.ts index af33f9221..db5c644ad 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -167,7 +167,13 @@ export const getSyncedBlock = cache( ); return cacheResponse(response, { revalidateBefore: 60 * 60, - tags: [], + tags: [ + getAPICacheTag({ + tag: 'synced-block', + organization: organizationId, + syncedBlock: syncedBlockId, + }), + ], }); } catch (error) { if ((error as GitBookAPIError).code === 404) { @@ -704,6 +710,12 @@ export function getAPICacheTag( | { tag: 'collection'; collection: string; + } + // All data related to a synced block + | { + tag: 'synced-block'; + syncedBlock: string; + organization: string; }, ): string { switch (spec.tag) { @@ -711,6 +723,8 @@ export function getAPICacheTag( return `space:${spec.space}`; case 'collection': return `collection:${spec.collection}`; + case 'synced-block': + return `synced-block:${spec.organization}:${spec.syncedBlock}`; default: assertNever(spec); }