Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a schema version to pull requests #96

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}