@crombolo/data 0.51.0 → 0.51.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/cluster.ts +20 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/data",
|
|
3
|
-
"version": "0.51.
|
|
3
|
+
"version": "0.51.1",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. SQLite and Postgres storage for crombolo: schema, migrations and repositories.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@crombolo/core": "0.51.
|
|
31
|
+
"@crombolo/core": "0.51.1",
|
|
32
32
|
"kysely": "0.29.6"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/cluster.ts
CHANGED
|
@@ -9,10 +9,16 @@ import { sql } from './query.ts'
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* `views` is a code change, not a data one: a template was written, so every
|
|
12
|
-
* node has to look at its views tree again.
|
|
13
|
-
* published cache; this one makes a node take a new snapshot.
|
|
12
|
+
* node has to look at its views tree again. `schema` and `content` invalidate
|
|
13
|
+
* the published cache; this one makes a node take a new snapshot. `public-files`
|
|
14
|
+
* is a site's `public/` folder changed by something a watcher cannot see, so a
|
|
15
|
+
* node lists it again (story 285).
|
|
14
16
|
*/
|
|
15
|
-
export type CacheInstructionKind = 'schema' | 'content' | 'components'
|
|
17
|
+
export type CacheInstructionKind = 'schema' | 'content' | 'components' | 'public-files'
|
|
18
|
+
|
|
19
|
+
/** Kinds about a site's files, not published content: they move no checkpoint. */
|
|
20
|
+
const isFileChange = (kind: CacheInstructionKind) =>
|
|
21
|
+
kind === 'components' || kind === 'public-files'
|
|
16
22
|
|
|
17
23
|
export interface CacheInstruction {
|
|
18
24
|
id: number
|
|
@@ -65,7 +71,7 @@ export function instructionEffects(
|
|
|
65
71
|
kind: CacheInstructionKind,
|
|
66
72
|
payload: Record<string, unknown>,
|
|
67
73
|
): InstructionEffects {
|
|
68
|
-
if (kind
|
|
74
|
+
if (isFileChange(kind)) return { pages: false, media: 'keep' }
|
|
69
75
|
if (kind === 'schema') return { pages: true, media: 'clear' }
|
|
70
76
|
const fields = Object.keys(payload)
|
|
71
77
|
const keys = strings(payload.media)
|
|
@@ -123,7 +129,7 @@ export async function appendCacheInstruction(
|
|
|
123
129
|
instruction: { kind: CacheInstructionKind; payload?: Record<string, unknown>; by?: string },
|
|
124
130
|
): Promise<number | null> {
|
|
125
131
|
return db.transaction(async (tx) => {
|
|
126
|
-
const checkpoint = instruction.kind
|
|
132
|
+
const checkpoint = isFileChange(instruction.kind) ? null : await advanceCheckpoint(tx)
|
|
127
133
|
await tx.q
|
|
128
134
|
.insertInto('cache_instruction')
|
|
129
135
|
.values({
|
|
@@ -223,6 +229,15 @@ export async function latestCacheInstructionId(db: Db): Promise<number> {
|
|
|
223
229
|
return Number(row?.n ?? 0)
|
|
224
230
|
}
|
|
225
231
|
|
|
232
|
+
/** The oldest instruction still held, or undefined when there are none. */
|
|
233
|
+
export async function oldestCacheInstructionId(db: Db): Promise<number | undefined> {
|
|
234
|
+
const row = await db.q
|
|
235
|
+
.selectFrom('cache_instruction')
|
|
236
|
+
.select((eb) => eb.fn.min('id').as('n'))
|
|
237
|
+
.executeTakeFirst()
|
|
238
|
+
return row?.n === null || row?.n === undefined ? undefined : Number(row.n)
|
|
239
|
+
}
|
|
240
|
+
|
|
226
241
|
export async function cacheInstructionsAfter(db: Db, afterId: number): Promise<CacheInstruction[]> {
|
|
227
242
|
const rows = await db.q
|
|
228
243
|
.selectFrom('cache_instruction')
|