Skip to content

Commit e8f6b01

Browse files
author
shashank dwivedi
committed
fix: skip shard reset for repos indexed within reindex interval
1 parent cbf9b3c commit e8f6b01

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

packages/backend/src/repoIndexManager.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -749,10 +749,6 @@ export class RepoIndexManager {
749749
return;
750750
}
751751

752-
// Read what shard files actually exist on disk and build a set
753-
// of repoIds that have at least one shard present.
754-
// Uses getRepoIdFromShardFileName to match the same naming convention
755-
// as cleanupOrphanedDiskResources (shards are named <orgId>_<repoId>_*.zoekt)
756752
const entries = await readdir(INDEX_CACHE_DIR);
757753
const repoIdsOnDisk = new Set<number>();
758754
for (const entry of entries) {
@@ -762,7 +758,6 @@ export class RepoIndexManager {
762758
}
763759
}
764760

765-
// Find all repos the DB believes are already indexed
766761
const indexedRepos = await this.db.repo.findMany({
767762
where: {
768763
indexedAt: {
@@ -772,17 +767,23 @@ export class RepoIndexManager {
772767
select: {
773768
id: true,
774769
name: true,
770+
indexedAt: true,
775771
},
776772
});
777773

778774
if (indexedRepos.length === 0) {
779775
return;
780776
}
781777

778+
// Only treat a missing shard as stale if indexedAt is older than
779+
// the reindex interval. This avoids resetting repos that legitimately
780+
// produce zero shards (e.g. empty repos).
781+
const thresholdDate = new Date(Date.now() - this.settings.reindexIntervalMs);
782+
782783
let resetCount = 0;
783784

784785
for (const repo of indexedRepos) {
785-
if (!repoIdsOnDisk.has(repo.id)) {
786+
if (!repoIdsOnDisk.has(repo.id) && repo.indexedAt! < thresholdDate) {
786787
logger.warn(`Repo "${repo.name}" (id: ${repo.id}) is marked as indexed in the DB but has no shard file on disk. Marking as stale.`);
787788
await this.db.repo.update({
788789
where: { id: repo.id },

0 commit comments

Comments
 (0)