mirror of
https://github.com/storytold/autocraft.git
synced 2026-12-01 10:33:55 +01:00
Dashboard reads: one settings snapshot per read request, read with the session; independent reads of the home, Now, inbox, item, item page and queue endpoints run together
This commit is contained in:
1 parent
d4e43572a0
commit
04a30c84cb
23 files changed
+430
-299
No files matched your search
+2
-1
@@ -10,6 +10,7 @@ import { DEFAULT_OWNER, OWNER } from "../owners.ts";
|
||||
import { AppNotInstalledError, TOKEN_ENV, appChildEnv, installationToken } from "./install-token.ts";
|
||||
import type { Db } from "../db/index.ts";
|
||||
import { dbFor, dbTarget, isPgUrl, openDb } from "../db/open.ts";
|
||||
import { setting } from "../settings-read.ts";
|
||||
|
||||
export type ReadEnv = Record<string, string>;
|
||||
export type ReadDeps = { db?: Db; mint?: (owner: string) => Promise<string>; defaultOwner?: () => Promise<string> };
|
||||
@@ -60,7 +61,7 @@ async function retried<T>(fn: () => Promise<T>): Promise<T> {
|
||||
}
|
||||
|
||||
const settingOf = (db: Db): Promise<string | undefined> =>
|
||||
retried(async () => (await db.get(db.k.selectFrom("main.settings").select("value").where("key", "=", "github_identity")))?.value ?? undefined);
|
||||
retried(async () => (await setting(db, "github_identity")) ?? undefined);
|
||||
|
||||
/** The identity setting as this process holds it, with the `settings` change counter it was read at (null: unknown). */
|
||||
let held: { app: boolean; seq: number | null } | null = null;
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ export const knownSlugs = async (db: Db): Promise<string[]> => parseSlugs(await
|
||||
/** Records `slug` in the persisted list when it is new. */
|
||||
export async function rememberSlug(db: Db, slug: string): Promise<void> {
|
||||
// Read from the table, not a pass snapshot: another connection may have recorded a slug since the pass began.
|
||||
const known = parseSlugs((await db.get(db.k.selectFrom("main.settings").select("value").where("key", "=", SLUGS_KEY)))?.value ?? undefined);
|
||||
const known = parseSlugs((await setting(db, SLUGS_KEY)) ?? undefined);
|
||||
if (known.includes(slug)) return;
|
||||
await writeSetting(db, SLUGS_KEY, JSON.stringify([...known, slug]));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user