perf(gateway): skip lifecycle session cache clone · openclaw/openclaw@0762aca
steipete
·
2026-05-27
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -20,6 +20,7 @@ import {
|
20 | 20 | readSessionUpdatedAt, |
21 | 21 | saveSessionStore, |
22 | 22 | updateSessionStore, |
| 23 | +updateSessionStoreEntry, |
23 | 24 | } from "./sessions/store.js"; |
24 | 25 | import type { SessionEntry } from "./sessions/types.js"; |
25 | 26 | |
@@ -579,6 +580,24 @@ describe("Session Store Cache", () => {
|
579 | 580 | expect(cached["session:1"].displayName).toBe("Writer owned"); |
580 | 581 | }); |
581 | 582 | |
| 583 | +it("can publish writer-owned entry patches directly into the object cache", async () => { |
| 584 | +await saveSessionStore(storePath, createSingleSessionStore()); |
| 585 | + |
| 586 | +const persisted = await updateSessionStoreEntry({ |
| 587 | + storePath, |
| 588 | +sessionKey: "session:1", |
| 589 | +takeCacheOwnership: true, |
| 590 | +update: async () => ({ |
| 591 | +displayName: "Entry writer owned", |
| 592 | +updatedAt: Date.now() + 1, |
| 593 | +}), |
| 594 | +}); |
| 595 | + |
| 596 | +const cached = loadSessionStore(storePath, { clone: false }); |
| 597 | +expect(cached["session:1"]).toBe(persisted); |
| 598 | +expect(cached["session:1"].displayName).toBe("Entry writer owned"); |
| 599 | +}); |
| 600 | + |
582 | 601 | it("builds immutable session snapshots lazily after writes", async () => { |
583 | 602 | await saveSessionStore(storePath, createSingleSessionStore()); |
584 | 603 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -633,13 +633,15 @@ async function persistResolvedSessionEntry(params: {
|
633 | 633 | store: Record<string, SessionEntry>; |
634 | 634 | resolved: ReturnType<typeof resolveSessionStoreEntry>; |
635 | 635 | next: SessionEntry; |
| 636 | +takeCacheOwnership?: boolean; |
636 | 637 | }): Promise<SessionEntry> { |
637 | 638 | params.store[params.resolved.normalizedKey] = params.next; |
638 | 639 | for (const legacyKey of params.resolved.legacyKeys) { |
639 | 640 | delete params.store[legacyKey]; |
640 | 641 | } |
641 | 642 | await saveSessionStoreUnlocked(params.storePath, params.store, { |
642 | 643 | activeSessionKey: params.resolved.normalizedKey, |
| 644 | +takeCacheOwnership: params.takeCacheOwnership, |
643 | 645 | }); |
644 | 646 | return params.next; |
645 | 647 | } |
@@ -648,6 +650,7 @@ export async function updateSessionStoreEntry(params: {
|
648 | 650 | storePath: string; |
649 | 651 | sessionKey: string; |
650 | 652 | update: (entry: SessionEntry) => Promise<Partial<SessionEntry> | null>; |
| 653 | +takeCacheOwnership?: boolean; |
651 | 654 | }): Promise<SessionEntry | null> { |
652 | 655 | const { storePath, sessionKey, update } = params; |
653 | 656 | return await runExclusiveSessionStoreWrite(storePath, async () => { |
@@ -667,6 +670,7 @@ export async function updateSessionStoreEntry(params: {
|
667 | 670 | store, |
668 | 671 | resolved, |
669 | 672 | next, |
| 673 | +takeCacheOwnership: params.takeCacheOwnership, |
670 | 674 | }); |
671 | 675 | }); |
672 | 676 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -160,6 +160,7 @@ export async function persistGatewaySessionLifecycleEvent(params: {
|
160 | 160 | await updateSessionStoreEntry({ |
161 | 161 | storePath: sessionEntry.storePath, |
162 | 162 | sessionKey: sessionEntry.canonicalKey, |
| 163 | +takeCacheOwnership: true, |
163 | 164 | update: async (entry) => |
164 | 165 | derivePersistedSessionLifecyclePatch({ |
165 | 166 | entry, |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。