diff --git a/apps/webapp/src/worker/instance.ts b/apps/webapp/src/worker/instance.ts index aa9acd1..5cc4698 100644 --- a/apps/webapp/src/worker/instance.ts +++ b/apps/webapp/src/worker/instance.ts @@ -2,7 +2,7 @@ import * as Comlink from "comlink"; import { groupBy, indexBy, prop, unique } from "remeda"; import { db } from "../lib/db"; import { splitQueries } from "@repo/github"; -import type { Pull } from "@repo/model"; +import { LATEST_SCHEMA_VERSION, type Pull } from "@repo/model"; import { GitHubClient, isInAttentionSet } from "@repo/github"; import { gitHubClient } from "../github"; @@ -92,7 +92,10 @@ export async function syncPullsOnce(client: GitHubClient, force: boolean = false if (previousKeys.has(res.uid)) { const previousPull = await db.pulls.get(res.uid); // Avoid fetching information if the pull request did not change. - if (previousPull !== undefined && res.updatedAt <= previousPull.updatedAt) { + if (previousPull !== undefined + && res.updatedAt <= previousPull.updatedAt + && previousPull.schemaVersion === LATEST_SCHEMA_VERSION + ) { stats.unchanged += 1; return previousPull; } else { @@ -110,6 +113,7 @@ export async function syncPullsOnce(client: GitHubClient, force: boolean = false connection: res.connection, sections: res.sections, host: connection.host, + schemaVersion: LATEST_SCHEMA_VERSION, starred: stars.has(res.uid) ? 1 : 0, attention: mayBeInAttentionSet ? isInAttentionSet(connection, pull) : undefined, } diff --git a/packages/model/src/pull.ts b/packages/model/src/pull.ts index 1f1dfc6..03c3b49 100644 --- a/packages/model/src/pull.ts +++ b/packages/model/src/pull.ts @@ -66,6 +66,11 @@ export type Attention = { reason?: string } +// Schema version is used to force bursting the local cache of pull requests +// when there is a change that requires it (e.g., adding a new field that must +// be populated). +export const LATEST_SCHEMA_VERSION = "v1"; + export type Pull = PullProps & { uid: string host: string @@ -73,4 +78,5 @@ export type Pull = PullProps & { sections: string[] attention?: Attention connection: string + schemaVersion?: string } \ No newline at end of file