Skip to content

Commit

Permalink
Address my own review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Thom Chiovoloni committed Feb 1, 2019
1 parent 95306c8 commit 167f2e9
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions components/places/src/storage/history.rs
Expand Up @@ -273,28 +273,30 @@ impl PageToClean {
fn cleanup_pages(db: &impl ConnExt, pages: &[PageToClean]) -> Result<()> {
// desktop does this frecency work using a function in a single sql
// statement - we should see if we can do that too.
let frec_ids: Vec<RowId> = pages
let frec_ids = pages
.iter()
.filter(|&p| p.has_foreign || p.has_visits)
.map(|p| p.id)
.collect();
.map(|p| p.id);

for id in frec_ids {
update_frecency(db.conn(), id, None)?;
}
let to_remove: Vec<&PageToClean> = pages
.into_iter()
.filter(|p| !p.has_foreign && !p.has_visits)
.collect();

// Like desktop, we do "AND foreign_count = 0 AND last_visit_date ISNULL"
// to creating orphans in case of async race conditions - in Desktop's
// case, it reads the pages before starting a write transaction, so that
// probably is possible. We don't currently do that, but might later, so
// we do it anyway.
let remove_ids: Vec<RowId> = to_remove.iter().map(|p| p.id).collect();
let remove_ids: Vec<RowId> = pages
.iter()
.filter(|p| !p.has_foreign && !p.has_visits)
.map(|p| p.id)
.collect();
sql_support::each_chunk(&remove_ids, |chunk, _| -> Result<()> {
// tombstones first.
db.conn().execute(
&format!("
&format!(
"
INSERT OR IGNORE INTO moz_places_tombstones (guid)
SELECT guid FROM moz_places
WHERE id in ({ids}) AND sync_status = {status}
Expand All @@ -307,7 +309,8 @@ fn cleanup_pages(db: &impl ConnExt, pages: &[PageToClean]) -> Result<()> {
chunk,
)?;
db.conn().execute(
&format!("
&format!(
"
DELETE FROM moz_places
WHERE id IN ({ids})
AND foreign_count = 0
Expand Down

0 comments on commit 167f2e9

Please sign in to comment.