Skip to content

Commit cc4f2f4

Browse files
Give the new Semble index tables the staleness column every index table carries
1 parent 5494d4a commit cc4f2f4

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

src/services/collection/collection-service.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,14 +2327,15 @@ export class CollectionService {
23272327
await this.pool.query(
23282328
`INSERT INTO cosmik_collections_index (
23292329
uri, cid, owner_did, name, description, access_type, created_at,
2330-
pds_url, indexed_at, updated_at
2331-
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, NOW(), NOW())
2330+
pds_url, indexed_at, updated_at, last_synced_at
2331+
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, NOW(), NOW(), NOW())
23322332
ON CONFLICT (uri) DO UPDATE SET
23332333
cid = EXCLUDED.cid,
23342334
name = EXCLUDED.name,
23352335
description = EXCLUDED.description,
23362336
access_type = EXCLUDED.access_type,
2337-
updated_at = NOW()`,
2337+
updated_at = NOW(),
2338+
last_synced_at = NOW()`,
23382339
[
23392340
metadata.uri,
23402341
metadata.cid,
@@ -2407,19 +2408,20 @@ export class CollectionService {
24072408
await this.pool.query(
24082409
`INSERT INTO cosmik_collection_links_index (
24092410
uri, cid, owner_did, card_uri, collection_uri, added_by, added_at,
2410-
is_removed, pds_url, indexed_at, updated_at
2411+
is_removed, pds_url, indexed_at, updated_at, last_synced_at
24112412
) VALUES (
24122413
$1, $2, $3, $4, $5, $6, $7,
24132414
COALESCE((SELECT is_removed FROM cosmik_collection_links_index WHERE uri = $1), false),
2414-
$8, NOW(), NOW()
2415+
$8, NOW(), NOW(), NOW()
24152416
)
24162417
ON CONFLICT (uri) DO UPDATE SET
24172418
cid = EXCLUDED.cid,
24182419
card_uri = EXCLUDED.card_uri,
24192420
collection_uri = EXCLUDED.collection_uri,
24202421
added_by = EXCLUDED.added_by,
24212422
added_at = EXCLUDED.added_at,
2422-
updated_at = NOW()`,
2423+
updated_at = NOW(),
2424+
last_synced_at = NOW()`,
24232425
[
24242426
metadata.uri,
24252427
metadata.cid,

src/storage/postgresql/migrations/1743300000000_cosmik-collection-links.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export function up(pgm: MigrationBuilder): void {
4747
pds_url: { type: 'text' },
4848
indexed_at: { type: 'timestamptz', notNull: true, default: pgm.func('NOW()') },
4949
updated_at: { type: 'timestamptz', notNull: true, default: pgm.func('NOW()') },
50+
// Every `*_index` table carries this: it is how a row's staleness against
51+
// the repository it came from is judged, and the compliance suite asserts
52+
// that none is missing it.
53+
last_synced_at: { type: 'timestamptz', notNull: true, default: pgm.func('NOW()') },
5054
});
5155

5256
pgm.createIndex('cosmik_collections_index', 'owner_did');
@@ -71,6 +75,7 @@ export function up(pgm: MigrationBuilder): void {
7175
pds_url: { type: 'text' },
7276
indexed_at: { type: 'timestamptz', notNull: true, default: pgm.func('NOW()') },
7377
updated_at: { type: 'timestamptz', notNull: true, default: pgm.func('NOW()') },
78+
last_synced_at: { type: 'timestamptz', notNull: true, default: pgm.func('NOW()') },
7479
});
7580

7681
// The read path asks "which collection is this card in", once per Semble

tests/compliance/database-compliance.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,12 +601,12 @@ describe('ATProto Database Compliance', () => {
601601
{
602602
name: 'Index semantics (_index naming)',
603603
query: `SELECT COUNT(*) as count FROM information_schema.tables WHERE table_schema = 'public' AND table_name LIKE '%_index'`,
604-
expected: 25, // eprints, reviews, endorsements, user_tags, relevance_logs, activity_log, authors, coauthor_claims, changelogs, annotations, entity_links, user_related_works, personal_graph_nodes, personal_graph_edges, collections, collection_edges, eprint_versions, cosmik_connections, cosmik_follows, margin_annotations, margin_bookmarks, cosmik_link_removals, collaboration_invites, collaboration_acceptances, muted_authors
604+
expected: 27, // eprints, reviews, endorsements, user_tags, relevance_logs, activity_log, authors, coauthor_claims, changelogs, annotations, entity_links, user_related_works, personal_graph_nodes, personal_graph_edges, collections, collection_edges, eprint_versions, cosmik_connections, cosmik_follows, cosmik_collections, cosmik_collection_links, margin_annotations, margin_bookmarks, cosmik_link_removals, collaboration_invites, collaboration_acceptances, muted_authors
605605
},
606606
{
607607
name: 'PDS source tracking',
608608
query: `SELECT COUNT(*) as count FROM information_schema.columns WHERE table_schema = 'public' AND table_name LIKE '%_index' AND column_name = 'pds_url'`,
609-
expected: 25, // All index tables have pds_url
609+
expected: 27, // All index tables have pds_url
610610
},
611611
{
612612
name: 'No blob data',

0 commit comments

Comments
 (0)