MCPcopy
hub / github.com/electerm/electerm / simulateWatcherOld

Function simulateWatcherOld

test/unit/db-concurrency.spec.js:133–150  ·  view source on GitHub ↗

* OLD watcher pattern (before fix): sequential one-by-one operations. * This is what caused the app to hang on large imports.

(dbName, action, { added, updated, removed })

Source from the content-addressed store, hash-verified

131 * This is what caused the app to hang on large imports.
132 */
133async function simulateWatcherOld (dbName, action, { added, updated, removed }) {
134 for (const item of removed) {
135 await action(dbName, 'remove', { _id: item.id })
136 }
137 for (const item of updated) {
138 await action(dbName, 'update', { _id: item.id }, { $set: item }, { upsert: false })
139 }
140 for (const item of added) {
141 await action(dbName, 'insert', item)
142 }
143 const allItems = await action(dbName, 'find', {})
144 const newOrder = allItems.map(d => d._id)
145 await action('data', 'update',
146 { _id: `${dbName}:order` },
147 { $set: { value: newOrder } },
148 { upsert: true }
149 )
150}
151
152/**
153 * NEW watcher pattern (after fix): batch insert + parallel remove/update + running guard.

Callers 1

Calls 1

actionFunction · 0.85

Tested by

no test coverage detected