fix: remove servers that no longer exist

Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
Infi 2024-08-20 04:06:40 +02:00
parent e102f6c310
commit 2071270ac0
3 changed files with 38 additions and 0 deletions

View File

@ -175,6 +175,21 @@ object RealtimeSocket {
) )
} }
// Remove servers that are not in the ready frame
val serversThatExist = readyFrame.servers.mapNotNull { it.id }
val serversInDatabase = database.serverQueries.selectAllIds().executeAsList()
val serversToDelete = serversInDatabase.filter { it !in serversThatExist }
serversToDelete.forEach {
database.serverQueries.delete(it)
Log.d(
"RealtimeSocket",
"Deleted server $it from local database due to not being in ready frame."
)
// Conversely, remove the server from the API state
RevoltAPI.serverCache.remove(it)
}
Log.d("RealtimeSocket", "Adding channels to cache.") Log.d("RealtimeSocket", "Adding channels to cache.")
val channelMap = readyFrame.channels.associateBy { it.id!! } val channelMap = readyFrame.channels.associateBy { it.id!! }
RevoltAPI.channelCache.putAll(channelMap) RevoltAPI.channelCache.putAll(channelMap)
@ -201,6 +216,21 @@ object RealtimeSocket {
) )
} }
// Remove channels that are not in the ready frame
val channelsThatExist = readyFrame.channels.mapNotNull { it.id }
val channelsInDatabase = database.channelQueries.selectAllIds().executeAsList()
val channelsToDelete = channelsInDatabase.filter { it !in channelsThatExist }
channelsToDelete.forEach {
database.channelQueries.delete(it)
Log.d(
"RealtimeSocket",
"Deleted channel $it from local database due to not being in ready frame."
)
// Conversely, remove the channel from the API state
RevoltAPI.channelCache.remove(it)
}
Log.d("RealtimeSocket", "Adding emojis to cache.") Log.d("RealtimeSocket", "Adding emojis to cache.")
val emojiMap = readyFrame.emojis.associateBy { it.id!! } val emojiMap = readyFrame.emojis.associateBy { it.id!! }
RevoltAPI.emojiCache.putAll(emojiMap) RevoltAPI.emojiCache.putAll(emojiMap)

View File

@ -24,6 +24,10 @@ selectAll:
SELECT * SELECT *
FROM Channel; FROM Channel;
selectAllIds:
SELECT id
FROM Channel;
upsert: upsert:
INSERT OR REPLACE INSERT OR REPLACE
INTO Channel (id, channelType, userId, name, owner, description, dmPartner, iconId, lastMessageId, active, nsfw, server) INTO Channel (id, channelType, userId, name, owner, description, dmPartner, iconId, lastMessageId, active, nsfw, server)

View File

@ -15,6 +15,10 @@ selectAll:
SELECT * SELECT *
FROM Server; FROM Server;
selectAllIds:
SELECT id
FROM Server;
upsert: upsert:
INSERT OR REPLACE INSERT OR REPLACE
INTO Server (id, owner, name, description, iconId, bannerId, flags) INTO Server (id, owner, name, description, iconId, bannerId, flags)