Skip to content

Commit

Permalink
fix cleanup error that prunes valid data
Browse files Browse the repository at this point in the history
  • Loading branch information
lezhnev74 committed Nov 15, 2024
1 parent 2016d9d commit 957fb99
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func ClearUp(db *DbContainer, ii *inverted_index_2.InvertedIndex) error {

// read ids as strings (helper)
strIds := func(sql string) (ids []string, uintIds []uint32, err error) {
r, err := db.Query("SELECT id FROM files")
r, err := db.Query(sql)
if err != nil {
return
}
Expand Down Expand Up @@ -63,7 +63,7 @@ func ClearUp(db *DbContainer, ii *inverted_index_2.InvertedIndex) error {

if len(danglingSegmentIds) > 0 {
segmentIdsString := strings.Join(danglingSegmentIds, ",")
_, err = db.Exec(fmt.Sprintf("DELETE FROM file_segments_messages WHERE segmentId NOT IN (%s)", segmentIdsString))
_, err = db.Exec(fmt.Sprintf("DELETE FROM file_segments_messages WHERE segmentId IN (%s)", segmentIdsString))
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func TestClearUp(t *testing.T) {
_, err = _db.Exec(`DELETE FROM files WHERE id=1`)
require.NoError(t, err)

test_util.DumpTable(_db.DB, "files", 2)
test_util.DumpTable(_db.DB, "file_segments", 6)
require.NoError(t, db.ClearUp(_db, ii))

// Assert files
Expand Down

0 comments on commit 957fb99

Please sign in to comment.