Added games: a reused ranking is not remembered as a fresh walk

A ranking a scan took from added-games-scan.json was also put in the
60-second in-memory cache with the current time, so for the next minute
single(), addFolder() and the exe picker, which ask for a fresh walk, got
a ranking that could be a week old. Kept rankings are now returned without
entering that cache, so it only ever holds rankings from real walks.
This commit is contained in:
K11MCH1 authored and Kurt Himebauch committed 2026-11-05 13:59:59 -05:00
1 parent df60fdb194
commit cb3c3cb2c9
2 files changed
+18 -1

No files matched your search

@@ -103,7 +103,7 @@ object AddedGames {
val key = "${folder.path}|${folder.lastModified()}"
val now = System.currentTimeMillis()
ranked[key]?.takeIf { now - it.first < RANK_FRESH_MS }?.let { return it.second }
if (reuse) kept?.rank(folder)?.let { ranked[key] = now to it; return it }
if (reuse) kept?.rank(folder)?.let { return it }
val guessed = GameExePicker.rank(folder) { !skipExe(it.name) }
val declared = declaredExes(folder)
val preferred = declared.map { it.path }.toSet()
@@ -111,6 +111,23 @@ class AddedGamesCacheTest {
assertEquals("Bastion", AddedGamesCache(file).name("named"))
}
@Test fun aRankingAScanReusedIsNotHandedToAFreshLookup() {
val folder = tmp.newFolder("Game")
val walked = File(folder, "Game.exe").apply { writeText("game") }
val kept = File(folder, "Other.exe").apply { writeText("other") }
val files = tmp.newFolder("files")
val context = object : android.content.ContextWrapper(app) {
override fun getFilesDir() = files
}
AddedGamesCache(File(files, AddedGamesCache.FILE)).apply {
keepRank(folder, GameExePicker.Ranking(listOf(kept), listOf(10), false))
save()
}
AddedGames.scan(context)
assertEquals(listOf(kept), AddedGames.rank(folder, reuse = true).exes)
assertEquals(walked, AddedGames.candidates(folder).first())
}
@Test fun aScanKeepsEachGamesRankingForTheNextLaunch() {
val (folder, exe) = game("Card Game")
AddedExes.put(app, AddedExes.Entry(folder.path, exe.path, picked = false))