Filter story info to just the relevant people in that specific dlist.

Co-authored-by: Greyson Parrelli <greyson@signal.org>
This commit is contained in:
Alex Hart
2022-10-24 20:14:40 -03:00
parent 48e0a00a8a
commit a15e97cc06
6 changed files with 51 additions and 6 deletions

View File

@@ -132,7 +132,7 @@ open class SignalDatabase(private val context: Application, databaseSecret: Data
executeStatements(db, GroupCallRingDatabase.CREATE_INDEXES)
executeStatements(db, NotificationProfileDatabase.CREATE_INDEXES)
executeStatements(db, DonationReceiptDatabase.CREATE_INDEXS)
db.execSQL(StorySendsDatabase.CREATE_INDEX)
executeStatements(db, StorySendsDatabase.CREATE_INDEXS)
executeStatements(db, DistributionListDatabase.CREATE_INDEXES)
executeStatements(db, PendingPniSignatureMessageDatabase.CREATE_INDEXES)

View File

@@ -5,6 +5,7 @@ import android.content.Context
import androidx.core.content.contentValuesOf
import org.signal.core.util.CursorUtil
import org.signal.core.util.SqlUtil
import org.signal.core.util.readToList
import org.signal.core.util.requireLong
import org.signal.core.util.select
import org.signal.core.util.toInt
@@ -43,9 +44,10 @@ class StorySendsDatabase(context: Context, databaseHelper: SignalDatabase) : Dat
)
""".trimIndent()
val CREATE_INDEX = """
CREATE INDEX story_sends_recipient_id_sent_timestamp_allows_replies_index ON $TABLE_NAME ($RECIPIENT_ID, $SENT_TIMESTAMP, $ALLOWS_REPLIES)
""".trimIndent()
val CREATE_INDEXS = arrayOf(
"CREATE INDEX story_sends_recipient_id_sent_timestamp_allows_replies_index ON $TABLE_NAME ($RECIPIENT_ID, $SENT_TIMESTAMP, $ALLOWS_REPLIES)",
"CREATE INDEX story_sends_message_id_distribution_id_index ON $TABLE_NAME ($MESSAGE_ID, $DISTRIBUTION_ID)",
)
}
fun insert(messageId: Long, recipientIds: Collection<RecipientId>, sentTimestamp: Long, allowsReplies: Boolean, distributionId: DistributionId) {
@@ -72,6 +74,18 @@ class StorySendsDatabase(context: Context, databaseHelper: SignalDatabase) : Dat
}
}
fun getRecipientsForDistributionId(messageId: Long, distributionId: DistributionId): Set<RecipientId> {
return readableDatabase
.select(RECIPIENT_ID)
.from(TABLE_NAME)
.where("$MESSAGE_ID = ? AND $DISTRIBUTION_ID = ?", messageId, distributionId.toString())
.run()
.readToList { cursor ->
RecipientId.from(cursor.requireLong(RECIPIENT_ID))
}
.toSet()
}
fun getRecipientsToSendTo(messageId: Long, sentTimestamp: Long, allowsReplies: Boolean): List<RecipientId> {
val recipientIds = mutableListOf<RecipientId>()

View File

@@ -15,6 +15,7 @@ import org.thoughtcrime.securesms.database.helpers.migration.V157_RecipeintHidde
import org.thoughtcrime.securesms.database.helpers.migration.V158_GroupsLastForceUpdateTimestampMigration
import org.thoughtcrime.securesms.database.helpers.migration.V159_ThreadUnreadSelfMentionCount
import org.thoughtcrime.securesms.database.helpers.migration.V160_SmsMmsExportedIndexMigration
import org.thoughtcrime.securesms.database.helpers.migration.V161_StorySendMessageIdIndex
/**
* Contains all of the database migrations for [SignalDatabase]. Broken into a separate file for cleanliness.
@@ -72,6 +73,10 @@ object SignalDatabaseMigrations {
if (oldVersion < 160) {
V160_SmsMmsExportedIndexMigration.migrate(context, db, oldVersion, newVersion)
}
if (oldVersion < 161) {
V161_StorySendMessageIdIndex.migrate(context, db, oldVersion, newVersion)
}
}
@JvmStatic

View File

@@ -0,0 +1,13 @@
package org.thoughtcrime.securesms.database.helpers.migration
import android.app.Application
import net.zetetic.database.sqlcipher.SQLiteDatabase
/**
* Adds an index to the story sends table to help with a new common query.
*/
object V161_StorySendMessageIdIndex : SignalDatabaseMigration {
override fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
db.execSQL("CREATE INDEX story_sends_message_id_distribution_id_index ON story_sends (message_id, distribution_id)")
}
}