Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (claude): batch consume-stamp via updateMany instead of N single writes
[._.]/ Adam Eivye8933e5db6ed
diff --git a/server/services/brain.js b/server/services/brain.jsindex f9679fc045..61b438a186 100644--- a/server/services/brain.js+++ b/server/services/brain.js@@ -689,11 +689,9 @@ export async function markInboxDone(inboxLogId) {*/export async function markInboxSentToCatalog(ids) {const sentToCatalogAt = new Date().toISOString();- const updated = [];- for (const id of ids) {- const entry = await storage.updateInboxLog(id, { sentToCatalogAt });- if (entry) updated.push(entry);- }+ // Single batched write (one store rewrite + one sync-log pass) — updateMany+ // already skips unknown/tombstoned ids, preserving the "stamp the rest" contract.+ const updated = await storage.updateMany('inbox', ids.map(id => ({ id, sentToCatalogAt })));console.log(`🧠 Marked ${updated.length} creative note(s) sent to catalog`);return updated;}diff --git a/server/services/brain.test.js b/server/services/brain.test.jsindex efbbf80b3b..904d163998 100644--- a/server/services/brain.test.js+++ b/server/services/brain.test.js@@ -13,6 +13,7 @@ vi.mock('./brainStorage.js', () => {getInboxLogById: vi.fn(),getInboxLogCounts: vi.fn(),updateInboxLog: vi.fn(),+ updateMany: vi.fn(),deleteInboxLog: vi.fn(),createPerson: vi.fn(),updatePerson: vi.fn(),@@ -544,27 +545,24 @@ describe('brain service', () => {// ===========================================================================describe('markInboxSentToCatalog', () => {- it('stamps sentToCatalogAt on each id and returns updated entries', async () => {- storage.updateInboxLog- .mockResolvedValueOnce({ id: 'inbox-001', sentToCatalogAt: 'x' })- .mockResolvedValueOnce({ id: 'inbox-002', sentToCatalogAt: 'x' });+ it('batches one updateMany stamping sentToCatalogAt on each id', async () => {+ storage.updateMany.mockResolvedValue([+ { id: 'inbox-001', sentToCatalogAt: 'x' },+ { id: 'inbox-002', sentToCatalogAt: 'x' }+ ]);const result = await markInboxSentToCatalog(['inbox-001', 'inbox-002']);- expect(storage.updateInboxLog).toHaveBeenCalledTimes(2);- expect(storage.updateInboxLog).toHaveBeenNthCalledWith(1, 'inbox-001', {- sentToCatalogAt: expect.any(String)- });- expect(storage.updateInboxLog).toHaveBeenNthCalledWith(2, 'inbox-002', {- sentToCatalogAt: expect.any(String)- });+ expect(storage.updateMany).toHaveBeenCalledTimes(1);+ expect(storage.updateMany).toHaveBeenCalledWith('inbox', [+ { id: 'inbox-001', sentToCatalogAt: expect.any(String) },+ { id: 'inbox-002', sentToCatalogAt: expect.any(String) }+ ]);expect(result).toHaveLength(2);});- it('skips ids that no longer exist (null update) without throwing', async () => {- storage.updateInboxLog- .mockResolvedValueOnce(null)- .mockResolvedValueOnce({ id: 'inbox-002', sentToCatalogAt: 'x' });+ it('returns only the entries updateMany applied (missing ids skipped)', async () => {+ storage.updateMany.mockResolvedValue([{ id: 'inbox-002', sentToCatalogAt: 'x' }]);const result = await markInboxSentToCatalog(['gone', 'inbox-002']);@@ -572,9 +570,12 @@ describe('brain service', () => {});it('returns an empty array for an empty id list', async () => {+ storage.updateMany.mockResolvedValue([]);+const result = await markInboxSentToCatalog([]);+expect(result).toEqual([]);- expect(storage.updateInboxLog).not.toHaveBeenCalled();+ expect(storage.updateMany).toHaveBeenCalledWith('inbox', []);});});