Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 44 additions & 17 deletions src/memory/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1131,9 +1131,19 @@ export class MemoryIndexManager {

const tasks = fileEntries.map((entry) => async () => {
const record = this.db
.prepare(`SELECT hash FROM files WHERE path = ? AND source = ?`)
.get(entry.path, "memory") as { hash: string } | undefined;
if (!params.needsFullReindex && record?.hash === entry.hash) {
const fileHashes = new Map<string, string>();
if (!params.needsFullReindex) {
const rows = this.db
.prepare(`SELECT path, hash FROM files WHERE source = ?`)
.all("memory") as Array<{ path: string; hash: string }>;
for (const row of rows) {
fileHashes.set(row.path, row.hash);
}
}

const tasks = fileEntries.map((entry) => async () => {
const existingHash = fileHashes.get(entry.path);
if (!params.needsFullReindex && existingHash === entry.hash) {
if (params.progress) {
params.progress.completed += 1;
params.progress.report({
Expand Down Expand Up @@ -1184,16 +1194,6 @@ export class MemoryIndexManager {
needsFullReindex: boolean;
progress?: MemorySyncProgressState;
}) {
const files = await this.listSessionFiles();
const activePaths = new Set(files.map((file) => this.sessionPathForFile(file)));
const indexAll = params.needsFullReindex || this.sessionsDirtyFiles.size === 0;
log.debug("memory sync: indexing session files", {
files: files.length,
indexAll,
dirtyFiles: this.sessionsDirtyFiles.size,
batch: this.batch.enabled,
concurrency: this.getIndexConcurrency(),
});
if (params.progress) {
params.progress.total += files.length;
params.progress.report({
Expand All @@ -1203,6 +1203,16 @@ export class MemoryIndexManager {
});
}

const fileHashes = new Map<string, string>();
if (!params.needsFullReindex) {
const rows = this.db
.prepare(`SELECT path, hash FROM files WHERE source = ?`)
.all("sessions") as Array<{ path: string; hash: string }>;
for (const row of rows) {
fileHashes.set(row.path, row.hash);
}
}

const tasks = files.map((absPath) => async () => {
if (!indexAll && !this.sessionsDirtyFiles.has(absPath)) {
if (params.progress) {
Expand All @@ -1225,10 +1235,8 @@ export class MemoryIndexManager {
}
return;
}
const record = this.db
.prepare(`SELECT hash FROM files WHERE path = ? AND source = ?`)
.get(entry.path, "sessions") as { hash: string } | undefined;
if (!params.needsFullReindex && record?.hash === entry.hash) {
const existingHash = fileHashes.get(entry.path);
if (!params.needsFullReindex && existingHash === entry.hash) {
if (params.progress) {
params.progress.completed += 1;
params.progress.report({
Expand All @@ -1248,6 +1256,25 @@ export class MemoryIndexManager {
total: params.progress.total,
});
}
});
params.progress.completed += 1;
params.progress.report({
completed: params.progress.completed,
total: params.progress.total,
});
}
this.resetSessionDelta(absPath, entry.size);
return;
}
await this.indexFile(entry, { source: "sessions", content: entry.content });
this.resetSessionDelta(absPath, entry.size);
if (params.progress) {
params.progress.completed += 1;
params.progress.report({
completed: params.progress.completed,
total: params.progress.total,
});
}
});
await this.runWithConcurrency(tasks, this.getIndexConcurrency());

Expand Down