only check once for filters v2 availability (#4539)

Instead of calling the endpoint every time filters are needed, it will
be called only once and the result cached. This will result in quite
some requests less on instances supporting v2.

I also tested v1 filters and made some small improvements. We should
[remove filters v1
support](https://github.com/tuskyapp/Tusky/issues/4538) some time in the
future though.
This commit is contained in:
Konrad Pozniak 2024-07-03 21:18:09 +02:00 committed by GitHub
commit 8a57bcc3f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 1470 additions and 127 deletions

View file

@ -62,14 +62,15 @@ import java.io.File;
},
// Note: Starting with version 54, database versions in Tusky are always even.
// This is to reserve odd version numbers for use by forks.
version = 62,
version = 64,
autoMigrations = {
@AutoMigration(from = 48, to = 49),
@AutoMigration(from = 49, to = 50, spec = AppDatabase.MIGRATION_49_50.class),
@AutoMigration(from = 50, to = 51),
@AutoMigration(from = 51, to = 52),
@AutoMigration(from = 53, to = 54), // hasDirectMessageBadge in AccountEntity
@AutoMigration(from = 56, to = 58) // translationEnabled in InstanceEntity/InstanceInfoEntity
@AutoMigration(from = 56, to = 58), // translationEnabled in InstanceEntity/InstanceInfoEntity
@AutoMigration(from = 62, to = 64) // filterV2Available in InstanceEntity
}
)
public abstract class AppDatabase extends RoomDatabase {

View file

@ -39,4 +39,10 @@ interface InstanceDao {
@RewriteQueriesToDropUnusedColumns
@Query("SELECT * FROM InstanceEntity WHERE instance = :instance LIMIT 1")
suspend fun getEmojiInfo(instance: String): EmojisEntity?
@Query("UPDATE InstanceEntity SET filterV2Supported = :filterV2Support WHERE instance = :instance")
suspend fun setFilterV2Support(instance: String, filterV2Support: Boolean)
@Query("SELECT filterV2Supported FROM InstanceEntity WHERE instance = :instance LIMIT 1")
suspend fun getFilterV2Support(instance: String): Boolean
}

View file

@ -15,6 +15,7 @@
package com.keylesspalace.tusky.db.entity
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverters
@ -41,6 +42,8 @@ data class InstanceEntity(
val maxFieldNameLength: Int?,
val maxFieldValueLength: Int?,
val translationEnabled: Boolean?,
// ToDo: Remove this again when filter v1 support is dropped
@ColumnInfo(defaultValue = "false") val filterV2Supported: Boolean = false
)
@TypeConverters(Converters::class)