@volter/teams 0.1.29 → 0.1.30

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/server/core.mjs +9 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/teams",
3
- "version": "0.1.29",
3
+ "version": "0.1.30",
4
4
  "type": "module",
5
5
  "description": "Volter Teams, the neutral team plane: machine identity and daemon core, the local door and server link, admission from machine grants, product doors, and the Teams server's neutral routes (company RFC 0008).",
6
6
  "license": "MIT",
package/server/core.mjs CHANGED
@@ -77,7 +77,13 @@ export async function maintain(api){const now=api.clock.nowMs();await api.store.
77
77
  AND NOT EXISTS (SELECT 1 FROM cursors c, json_each(c.snapshot_json) j WHERE c.team_id=v.team_id AND c.kind IN ('list','search') AND c.expires_at>? AND json_extract(j.value,'$[0]')=v.session_id AND json_extract(j.value,'$[1]')=v.revision)
78
78
  AND NOT EXISTS (SELECT 1 FROM cursors c WHERE c.team_id=v.team_id AND c.kind='history' AND c.expires_at>? AND json_extract(c.snapshot_json,'$.session_id')=v.session_id AND json_extract(c.snapshot_json,'$.revision')=v.revision)
79
79
  LIMIT ${VERSION_PRUNE_BATCH}`,[now,now]);
80
+ // A committed capture's parts are its messages in transit; once committed, the session's version holds them, so
81
+ // they go (a backlog of them filled the database).
82
+ const parts=await api.store.query(`SELECT p.team_id,p.capture_id,p.part_index FROM capture_parts p JOIN captures c ON c.team_id=p.team_id AND c.id=p.capture_id WHERE c.state='committed' LIMIT ${PART_PRUNE_BATCH}`,[]);
83
+ if(parts.length)await api.store.transaction(parts.map(({team_id,capture_id,part_index})=>({sql:'DELETE FROM capture_parts WHERE team_id=? AND capture_id=? AND part_index=?',params:[team_id,capture_id,part_index]})));
80
84
  if(stale.length)await api.store.transaction(stale.flatMap(({team_id,session_id,revision})=>['messages','session_artifacts','session_versions'].map(table=>({sql:`DELETE FROM ${table} WHERE team_id=? AND session_id=? AND revision=?`,params:[team_id,session_id,revision]}))));
81
- return {pruned_versions:stale.length};}
82
- /** Session versions `maintain` removes per run: small enough for one Durable Object alarm, drains a backlog in hours. */
83
- const VERSION_PRUNE_BATCH=50;
85
+ return {pruned_versions:stale.length,pruned_parts:parts.length,backlog:stale.length>=VERSION_PRUNE_BATCH||parts.length>=PART_PRUNE_BATCH};}
86
+ /** Session versions `maintain` removes per run: small enough for one Durable Object alarm; a backlog runs again in seconds. */
87
+ const VERSION_PRUNE_BATCH=200;
88
+ /** Committed capture parts `maintain` removes per run. */
89
+ const PART_PRUNE_BATCH=500;