Merge pull request #287 from PR0M3TH3AN/perf/optimize-pruner-lifecycle-15735036455677538666

⚡ Parallelize memory lifecycle actions in pruner
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2026-02-17 22:41:48 -05:00
commit 11c7510b95
2 files changed
+18 -9

No files matched your search

+3 -5
View File
@@ -272,9 +272,7 @@ export async function createLifecyclePlan(memories, options) {
* @param {Awaited<ReturnType<typeof createLifecyclePlan>>} plan
*/
export async function applyLifecycleActions(repository, plan) {
const results = [];
for (const decision of plan.actions) {
const results = await Promise.all(plan.actions.map(async (decision) => {
if (decision.merged_into && typeof repository.markMerged === 'function') {
await repository.markMerged(decision.id, decision.merged_into);
}
@@ -287,8 +285,8 @@ export async function applyLifecycleActions(repository, plan) {
await repository.keepMemory?.(decision.id, decision.reason);
}
results.push(decision);
}
return decision;
}));
return {
applied: results,
+15 -4
View File
@@ -138,11 +138,22 @@ test('applyLifecycleActions executes keep/archive/delete and merge markers', asy
policyLogs: [],
});
assert.deepEqual(calls, [
['keepMemory', 'k1', 'keep reason'],
['markMerged', 'a1', 'k1'],
// Sort calls to verify presence regardless of execution order
const sortedCalls = [...calls].sort((a, b) => a[0].localeCompare(b[0]) || a[1].localeCompare(b[1]));
const expectedCalls = [
['archiveMemory', 'a1', 'archive reason'],
['deleteMemory', 'd1', 'delete reason'],
]);
['keepMemory', 'k1', 'keep reason'],
['markMerged', 'a1', 'k1'],
];
assert.deepEqual(sortedCalls, expectedCalls);
// Verify that markMerged happens before archiveMemory for the same ID
const markIndex = calls.findIndex((c) => c[0] === 'markMerged' && c[1] === 'a1');
const archiveIndex = calls.findIndex((c) => c[0] === 'archiveMemory' && c[1] === 'a1');
assert.ok(markIndex !== -1, 'markMerged was called');
assert.ok(archiveIndex !== -1, 'archiveMemory was called');
assert.ok(markIndex < archiveIndex, 'markMerged should precede archiveMemory');
assert.equal(result.applied.length, 3);
});