Skip to content

Commit ea413ce

Browse files
committed
feature-233-implement-openrouter: Add removeChunksByShasum method to SupabaseRepository and integrate it into VectorActionUseCase
- Implemented a new method in SupabaseRepository to remove chunks based on their SHA256 checksum. - Integrated the new method into VectorActionUseCase to handle cases where the number of remote chunked files differs from local chunked files, ensuring proper cleanup in Supabase. - Enhanced logging for better tracking of chunk removal operations.
1 parent d05e043 commit ea413ce

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/data/repository/supabase_repository.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,30 @@ export class SupabaseRepository {
5151
}
5252
}
5353

54+
removeChunksByShasum = async (
55+
owner: string,
56+
repository: string,
57+
branch: string,
58+
shasum: string,
59+
): Promise<void> => {
60+
try {
61+
const { error } = await this.supabase
62+
.from(this.CHUNKS_TABLE)
63+
.delete()
64+
.eq('owner', owner)
65+
.eq('repository', repository)
66+
.eq('branch', branch)
67+
.eq('shasum', shasum);
68+
69+
if (error) {
70+
throw error;
71+
}
72+
} catch (error) {
73+
logError(`Error removing chunks by shasum: ${JSON.stringify(error, null, 2)}`);
74+
throw error;
75+
}
76+
}
77+
5478
getChunkedFileByShasum = async (
5579
owner: string,
5680
repository: string,

src/usecase/vector_action_use_case.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ export class VectorActionUseCase implements ParamUseCase<Execution, Result[]> {
9696
continue;
9797
} else if (remoteChunkedFiles.length > 0 && remoteChunkedFiles.length !== chunkedFile.chunks.length) {
9898
logDebugInfo(`📦 ❌ Chunk has a different number of chunks in Supabase: [${chunkedFile.path}] [${chunkedFile.index}]`, true);
99+
await supabaseRepository.removeChunksByShasum(
100+
param.owner,
101+
param.repo,
102+
param.commit.branch,
103+
chunkedFile.shasum,
104+
);
105+
logDebugInfo(`📦 🗑️ Chunks removed from Supabase: [${chunkedFile.path}] [${chunkedFile.index}]`, true);
99106
}
100107

101108
logSingleLine(`🟡 ${i + 1}/${totalFiles} (${progress.toFixed(1)}%) - Estimated time remaining: ${Math.ceil(remainingTime)} seconds | Vectorizing [${chunkedFile.path}]`);

0 commit comments

Comments
 (0)