[db] deprecate caching of localized app name and summary

This led to many hard to debug issues in the past. It is easier to always fetch fresh data and not cache it.

Previously, we needed the cache as a search index. Now, search uses all localizations, so the cache isn't needed anymore.
This commit is contained in:
Torsten Grote
2025-09-01 15:50:43 -03:00
parent 290cfcee34
commit 3284745c81
5 changed files with 27 additions and 6 deletions

View File

@@ -481,7 +481,8 @@ internal class AppOverviewItemsTest : AppTest() {
assertEquals(expected.lastUpdated, actual.lastUpdated)
assertEquals(expected.name.getBestLocale(locales), actual.name)
assertEquals(expected.summary.getBestLocale(locales), actual.summary)
assertEquals(expected.summary.getBestLocale(locales), actual.summary)
assertEquals(expected.name.getBestLocale(locales), actual.getName(locales))
assertEquals(expected.summary.getBestLocale(locales), actual.getSummary(locales))
assertEquals(expected.icon.getBestLocale(locales), actual.getIcon(locales))
}

View File

@@ -285,9 +285,15 @@ public data class AppOverviewItem internal constructor(
public val added: Long,
public val lastUpdated: Long,
@ColumnInfo(name = "localizedName")
@Deprecated("Use getName() method instead.")
public override val name: String? = null,
@ColumnInfo(name = "localizedSummary")
@Deprecated("Use getSummary() method instead.")
public override val summary: String? = null,
@ColumnInfo(name = "name")
internal val internalName: LocalizedTextV2? = null,
@ColumnInfo(name = "summary")
internal val internalSummary: LocalizedTextV2? = null,
public val categories: List<String>? = null,
internal val antiFeatures: Map<String, LocalizedTextV2>? = null,
@Relation(
@@ -300,6 +306,14 @@ public data class AppOverviewItem internal constructor(
*/
public val isCompatible: Boolean,
) : MinimalApp {
public fun getName(localeList: LocaleListCompat): String? {
return internalName.getBestLocale(localeList)
}
public fun getSummary(localeList: LocaleListCompat): String? {
return internalSummary.getBestLocale(localeList)
}
public override fun getIcon(localeList: LocaleListCompat): FileV2? {
return localizedIcon?.filter { icon ->
icon.repoId == repoId

View File

@@ -376,6 +376,7 @@ internal interface AppDaoInt : AppDao {
WHERE repoId = :repoId""")
override fun updateCompatibility(repoId: Long)
@Deprecated("Will be removed in future version")
@Query("""UPDATE ${AppMetadata.TABLE} SET localizedName = :name, localizedSummary = :summary
WHERE repoId = :repoId AND packageName = :packageName""")
fun updateAppMetadata(repoId: Long, packageName: String, name: String?, summary: String?)
@@ -423,7 +424,7 @@ internal interface AppDaoInt : AppDao {
@Transaction
@Query("""SELECT repoId, packageName, app.added, app.lastUpdated, localizedName,
localizedSummary, categories, version.antiFeatures, app.isCompatible
localizedSummary, app.name, summary, categories, version.antiFeatures, app.isCompatible
FROM ${AppMetadata.TABLE} AS app
JOIN ${RepositoryPreferences.TABLE} AS pref USING (repoId)
JOIN PreferredRepo USING (packageName)
@@ -438,7 +439,7 @@ internal interface AppDaoInt : AppDao {
@Transaction
@Query("""SELECT repoId, packageName, app.added, app.lastUpdated, localizedName,
localizedSummary, categories, version.antiFeatures, app.isCompatible
localizedSummary, app.name, summary, categories, version.antiFeatures, app.isCompatible
FROM ${AppMetadata.TABLE} AS app
JOIN ${RepositoryPreferences.TABLE} AS pref USING (repoId)
JOIN PreferredRepo USING (packageName)
@@ -458,7 +459,7 @@ internal interface AppDaoInt : AppDao {
@Transaction
@SuppressWarnings(QUERY_MISMATCH) // no anti-features needed here
@Query("""SELECT repoId, packageName, added, app.lastUpdated, localizedName,
localizedSummary, categories, app.isCompatible
localizedSummary, name, summary, categories, app.isCompatible
FROM ${AppMetadata.TABLE} AS app WHERE repoId = :repoId AND packageName = :packageName""")
fun getAppOverviewItem(repoId: Long, packageName: String): AppOverviewItem?
@@ -508,7 +509,7 @@ internal interface AppDaoInt : AppDao {
@Transaction
@Query("""SELECT repoId, packageName, app.added, app.lastUpdated, localizedName,
localizedSummary, categories, version.antiFeatures, app.isCompatible
localizedSummary, name, summary, categories, version.antiFeatures, app.isCompatible
FROM ${AppMetadata.TABLE} AS app
LEFT JOIN ${HighestVersion.TABLE} AS version USING (repoId, packageName)
WHERE repoId = :repoId""")
@@ -543,7 +544,7 @@ internal interface AppDaoInt : AppDao {
val queryBuilder = StringBuilder(
"""
SELECT repoId, packageName, app.added, app.lastUpdated, localizedName,
localizedSummary, categories, version.antiFeatures, app.isCompatible
localizedSummary, name, summary, categories, version.antiFeatures, app.isCompatible
FROM ${AppMetadata.TABLE} AS app
JOIN PreferredRepo USING (packageName)
LEFT JOIN ${HighestVersion.TABLE} AS version USING (repoId, packageName)

View File

@@ -60,6 +60,8 @@ internal abstract class FDroidDatabaseInt : RoomDatabase(), FDroidDatabase, Clos
abstract override fun getAppDao(): AppDaoInt
abstract override fun getVersionDao(): VersionDaoInt
abstract override fun getAppPrefsDao(): AppPrefsDaoInt
@Deprecated("Will be removed in future version")
override fun afterLocalesChanged(locales: LocaleListCompat) {
val appDao = getAppDao()
runInTransaction {
@@ -119,6 +121,7 @@ public interface FDroidDatabase {
* Call this after the system [Locale]s have changed.
* If this isn't called, the cached localized app metadata (e.g. name, summary) will be wrong.
*/
@Deprecated("Will be removed in future version")
public fun afterLocalesChanged(
locales: LocaleListCompat = getLocales(Resources.getSystem().configuration),
)

View File

@@ -61,6 +61,8 @@ internal open class RepoV2StreamReceiver(
lastUpdated = p.metadata.lastUpdated,
name = p.metadata.name.getBestLocale(locales),
summary = p.metadata.summary.getBestLocale(locales),
internalName = p.metadata.name,
internalSummary = p.metadata.summary,
antiFeatures = p.versions.values.lastOrNull()?.antiFeatures,
localizedIcon = p.metadata.icon?.map { (locale, file) ->
LocalizedIcon(