Skip to content

Commit

Permalink
feat: add a schema version to pull requests (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
pvcnt authored Aug 27, 2024
1 parent 024a6eb commit 9c6ef36
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions apps/webapp/src/worker/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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 {
Expand All @@ -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,
}
Expand Down
6 changes: 6 additions & 0 deletions packages/model/src/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,17 @@ 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
starred: number // boolean is not indexable.
sections: string[]
attention?: Attention
connection: string
schemaVersion?: string
}

0 comments on commit 9c6ef36

Please sign in to comment.