A fork of attic a self-hostable Nix Binary Cache server
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix chunk deletion bug (#67)

authored by

Zhaofeng Li and committed by
GitHub
4902d57f b1e512e0

+13 -8
+13 -8
server/src/gc.rs
··· 177 177 // ... and transition their state to Deleted 178 178 // 179 179 // Deleted chunks are essentially invisible from our normal queries 180 - let change_state = Query::update() 181 - .table(Chunk) 182 - .value(chunk::Column::State, ChunkState::Deleted) 183 - .and_where(chunk::Column::Id.in_subquery(orphan_chunk_ids)) 184 - .returning_all() 185 - .to_owned(); 180 + let transition_statement = { 181 + let change_state = Query::update() 182 + .table(Chunk) 183 + .value(chunk::Column::State, ChunkState::Deleted) 184 + .and_where(chunk::Column::Id.in_subquery(orphan_chunk_ids)) 185 + .to_owned(); 186 + db.get_database_backend().build(&change_state) 187 + }; 186 188 187 - let stmt = db.get_database_backend().build(&change_state); 189 + db.execute(transition_statement).await?; 188 190 189 - let orphan_chunks = chunk::Model::find_by_statement(stmt).all(db).await?; 191 + let orphan_chunks: Vec<chunk::Model> = Chunk::find() 192 + .filter(chunk::Column::State.eq(ChunkState::Deleted)) 193 + .all(db) 194 + .await?; 190 195 191 196 if orphan_chunks.is_empty() { 192 197 return Ok(());