Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1131737 - Expire history and favicons (#4068)
* Bug 1131737 - Expire history and favicons * Added test case for cleaning up old history/visits to StoragePerfTests.
- Loading branch information
1 parent
a4ff32c
commit e613114
Showing
2 changed files
with
71 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,15 +171,52 @@ extension SQLiteHistory: HistoryRecommendations { | |
return [(clearHighlightsQuery, nil), (sql, args)] | ||
} | ||
|
||
public func repopulate(invalidateTopSites shouldInvalidateTopSites: Bool, invalidateHighlights shouldInvalidateHighlights: Bool) -> Success { | ||
var queries: [(String, Args?)] = [] | ||
if shouldInvalidateTopSites { | ||
queries.append(contentsOf: self.refreshTopSitesQuery()) | ||
// Checks if there are more than 100k items in the `visits` table. | ||
// This is used as an indicator that we should clean up old history. | ||
func checkIfCleanupIsNeeded() -> Deferred<Maybe<Bool>> { | ||
let sql = "SELECT COUNT(*) FROM \(TableVisits)" | ||
This comment has been minimized.
Sorry, something went wrong. |
||
return self.db.runQuery(sql, args: nil, factory: IntFactory) >>== { cursor in | ||
guard let visitCount = cursor[0], visitCount > 100000 else { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rnewman
Contributor
|
||
return deferMaybe(false) | ||
} | ||
|
||
return deferMaybe(true) | ||
} | ||
if shouldInvalidateHighlights { | ||
queries.append(contentsOf: self.repopulateHighlightsQuery()) | ||
} | ||
|
||
// Deletes the oldest 50k items from the `visits` table and their | ||
// corresponding items in the `history` table. This only gets run when | ||
// there are more than 100k items in the `visits` table. Because of | ||
// this, we may need to clean up several times until we've crossed | ||
// below the 100k-item threshold. | ||
private func cleanupOldHistory() -> [(String, Args?)] { | ||
let visitsSQL = """ | ||
DELETE FROM \(TableVisits) WHERE id IN ( | ||
SELECT id FROM \(TableVisits) ORDER BY \(TableVisits).date ASC LIMIT 50000 | ||
This comment has been minimized.
Sorry, something went wrong.
rnewman
Contributor
|
||
) | ||
""" | ||
let historySQL = """ | ||
DELETE FROM \(TableHistory) WHERE NOT EXISTS ( | ||
SELECT 1 FROM \(TableVisits) WHERE \(TableVisits).siteID = \(TableHistory).id | ||
) | ||
""" | ||
return [(visitsSQL, nil), (historySQL, nil)] | ||
} | ||
|
||
public func repopulate(invalidateTopSites shouldInvalidateTopSites: Bool, invalidateHighlights shouldInvalidateHighlights: Bool) -> Success { | ||
return checkIfCleanupIsNeeded() >>== { doCleanup in | ||
var queries: [(String, Args?)] = [] | ||
if doCleanup { | ||
queries.append(contentsOf: self.cleanupOldHistory()) | ||
} | ||
if shouldInvalidateTopSites { | ||
queries.append(contentsOf: self.refreshTopSitesQuery()) | ||
} | ||
if shouldInvalidateHighlights { | ||
queries.append(contentsOf: self.repopulateHighlightsQuery()) | ||
} | ||
return self.db.run(queries) | ||
} | ||
return self.db.run(queries) | ||
} | ||
|
||
public func getRecentBookmarks(_ limit: Int = 3) -> Deferred<Maybe<Cursor<Site>>> { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
No! @justindarc query history, not visits.
100,000 visits ain't that much. My desktop Places has 250K places and 450K visits.