Changeset 57929aa in Klonkt


Ignore:
Timestamp:
06/16/2026 01:15:27 AM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
0908b8f
Parents:
0b7ebbf
Message:

Circles: lazy prepares in CircleService (fix crash on boot)

The module-level db.prepare() ran at import — before initializeDatabase()
created the remote_actors/remote_posts tables -> SQLITE_ERROR no such table
-> crash-loop. Now lazy via stmts() (prepare on first sync).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/services/CircleService.js

    r0b7ebbf r57929aa  
    4747}
    4848
    49 const upsertActor = db.prepare(`
    50   INSERT INTO remote_actors (id, url, name, summary, avatar, public_key, fetched_at)
    51   VALUES (@id, @url, @name, @summary, @avatar, @public_key, CURRENT_TIMESTAMP)
    52   ON CONFLICT(id) DO UPDATE SET
    53     url=excluded.url, name=excluded.name, summary=excluded.summary,
    54     avatar=excluded.avatar, public_key=excluded.public_key, fetched_at=CURRENT_TIMESTAMP
    55 `);
    56 const upsertPost = db.prepare(`
    57   INSERT INTO remote_posts (id, actor_id, published, title, summary, url, media_json, raw_json, fetched_at)
    58   VALUES (@id, @actor_id, @published, @title, @summary, @url, @media_json, @raw_json, CURRENT_TIMESTAMP)
    59   ON CONFLICT(id) DO UPDATE SET
    60     published=excluded.published, title=excluded.title, summary=excluded.summary,
    61     url=excluded.url, media_json=excluded.media_json, raw_json=excluded.raw_json, fetched_at=CURRENT_TIMESTAMP
    62 `);
     49// Lazy prepares — de tabellen bestaan pas ná initializeDatabase(); dit module
     50// wordt geïmporteerd vóór die call, dus niet op module-niveau prepare'n.
     51let _stmts = null;
     52function stmts() {
     53  if (_stmts) return _stmts;
     54  _stmts = {
     55    upsertActor: db.prepare(`
     56      INSERT INTO remote_actors (id, url, name, summary, avatar, public_key, fetched_at)
     57      VALUES (@id, @url, @name, @summary, @avatar, @public_key, CURRENT_TIMESTAMP)
     58      ON CONFLICT(id) DO UPDATE SET
     59        url=excluded.url, name=excluded.name, summary=excluded.summary,
     60        avatar=excluded.avatar, public_key=excluded.public_key, fetched_at=CURRENT_TIMESTAMP
     61    `),
     62    upsertPost: db.prepare(`
     63      INSERT INTO remote_posts (id, actor_id, published, title, summary, url, media_json, raw_json, fetched_at)
     64      VALUES (@id, @actor_id, @published, @title, @summary, @url, @media_json, @raw_json, CURRENT_TIMESTAMP)
     65      ON CONFLICT(id) DO UPDATE SET
     66        published=excluded.published, title=excluded.title, summary=excluded.summary,
     67        url=excluded.url, media_json=excluded.media_json, raw_json=excluded.raw_json, fetched_at=CURRENT_TIMESTAMP
     68    `),
     69  };
     70  return _stmts;
     71}
    6372
    6473export async function syncOne(link) {
     
    8190  }
    8291
    83   upsertActor.run({
     92  stmts().upsertActor.run({
    8493    id: actorId,
    8594    url: actor.url || base,
     
    116125      }
    117126    }
    118     upsertPost.run({
     127    stmts().upsertPost.run({
    119128      id: obj.id,
    120129      actor_id: actorId,
Note: See TracChangeset for help on using the changeset viewer.