2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-09 19:10:42 +00:00

No issue: Use ExcludeTypes instead of filtering after retrieving

This commit is contained in:
Emily Kager 2019-05-15 17:23:01 -07:00 committed by Jeff Boek
parent a02bf550c8
commit 40f8e3b6af

View File

@ -232,23 +232,27 @@ class HistoryFragment : Fragment(), CoroutineScope, BackHandler {
override fun onBackPressed(): Boolean = (historyComponent.uiView as HistoryUIView).onBackPressed()
private suspend fun reloadData() {
val allowedVisitTypes = listOf(VisitType.LINK, VisitType.TYPED, VisitType.BOOKMARK)
val excludeTypes = listOf(
VisitType.NOT_A_VISIT,
VisitType.DOWNLOAD,
VisitType.REDIRECT_TEMPORARY,
VisitType.RELOAD,
VisitType.EMBED,
VisitType.FRAMED_LINK,
VisitType.REDIRECT_PERMANENT
)
// Until we have proper pagination, only display a limited set of history to avoid blowing up the UI.
// See https://github.com/mozilla-mobile/fenix/issues/1393
@SuppressWarnings("MagicNumber")
val historyCutoffMs = 1000L * 60 * 60 * 24 * 3 // past few days
val items = requireComponents.core.historyStorage.getDetailedVisits(
System.currentTimeMillis() - historyCutoffMs
System.currentTimeMillis() - historyCutoffMs, excludeTypes = excludeTypes
)
// We potentially have a large amount of visits, and multiple processing steps.
// Wrapping iterator in a sequence should make this a little more efficient.
.asSequence()
.sortedByDescending { it.visitTime }
// Temporary filtering until we can do it at the API level.
// See https://github.com/mozilla-mobile/android-components/issues/2643
.filter { allowedVisitTypes.contains(it.visitType) }
.mapIndexed { id, item ->
HistoryItem(
id, if (TextUtils.isEmpty(item.title!!)) try {