@crombolo/data 0.52.2 → 0.53.2
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 +21 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/data",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.2",
|
|
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.
|
|
31
|
+
"@crombolo/core": "0.53.2",
|
|
32
32
|
"kysely": "0.29.6"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/cluster.ts
CHANGED
|
@@ -276,42 +276,34 @@ export async function touchServer(db: Db, identity: ServerIdentity): Promise<voi
|
|
|
276
276
|
const now = DbDate.toDb(new Date())
|
|
277
277
|
const role = identity.role ?? null
|
|
278
278
|
const crombolo = identity.cromboloVersion ?? null
|
|
279
|
-
const existing = await db.q
|
|
280
|
-
.selectFrom('server')
|
|
281
|
-
.select('node_id')
|
|
282
|
-
.where('node_id', '=', identity.nodeId)
|
|
283
|
-
.executeTakeFirst()
|
|
284
279
|
const served = identity.served?.checkpoint ?? null
|
|
285
280
|
const servedAt = identity.served ? DbDate.toDb(identity.served.at) : null
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
281
|
+
// One statement, so a boot and a poll writing at once can't both find no row and
|
|
282
|
+
// both insert one.
|
|
283
|
+
await db.q
|
|
284
|
+
.insertInto('server')
|
|
285
|
+
.values({
|
|
286
|
+
node_id: identity.nodeId,
|
|
287
|
+
version: identity.version,
|
|
288
|
+
revision: identity.revision,
|
|
289
|
+
role,
|
|
290
|
+
crombolo_version: crombolo,
|
|
291
|
+
last_seen: now,
|
|
292
|
+
served_checkpoint: served,
|
|
293
|
+
served_at: servedAt,
|
|
294
|
+
})
|
|
295
|
+
.onConflict((conflict) =>
|
|
296
|
+
conflict.column('node_id').doUpdateSet({
|
|
290
297
|
version: identity.version,
|
|
291
298
|
revision: identity.revision,
|
|
292
299
|
role,
|
|
293
300
|
crombolo_version: crombolo,
|
|
294
301
|
last_seen: now,
|
|
295
|
-
served_checkpoint: sql<number>`coalesce(${served}, ${sql.ref('served_checkpoint')})`,
|
|
296
|
-
served_at: sql<string>`coalesce(${servedAt}, ${sql.ref('served_at')})`,
|
|
297
|
-
})
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
} else {
|
|
301
|
-
await db.q
|
|
302
|
-
.insertInto('server')
|
|
303
|
-
.values({
|
|
304
|
-
node_id: identity.nodeId,
|
|
305
|
-
version: identity.version,
|
|
306
|
-
revision: identity.revision,
|
|
307
|
-
role,
|
|
308
|
-
crombolo_version: crombolo,
|
|
309
|
-
last_seen: now,
|
|
310
|
-
served_checkpoint: served,
|
|
311
|
-
served_at: servedAt,
|
|
312
|
-
})
|
|
313
|
-
.execute()
|
|
314
|
-
}
|
|
302
|
+
served_checkpoint: sql<number>`coalesce(${served}, ${sql.ref('server.served_checkpoint')})`,
|
|
303
|
+
served_at: sql<string>`coalesce(${servedAt}, ${sql.ref('server.served_at')})`,
|
|
304
|
+
}),
|
|
305
|
+
)
|
|
306
|
+
.execute()
|
|
315
307
|
}
|
|
316
308
|
|
|
317
309
|
export interface LiveNode {
|