limit the number of returned members to the last 300

pull/1693/head
Audric Ackermann 4 years ago
parent 27fb732f50
commit 9796f6fd52
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -126,6 +126,8 @@ const ITEMS_TABLE = 'items';
const ATTACHMENT_DOWNLOADS_TABLE = 'attachment_downloads'; const ATTACHMENT_DOWNLOADS_TABLE = 'attachment_downloads';
const CLOSED_GROUP_V2_KEY_PAIRS_TABLE = 'encryptionKeyPairsForClosedGroupV2'; const CLOSED_GROUP_V2_KEY_PAIRS_TABLE = 'encryptionKeyPairsForClosedGroupV2';
const MAX_PUBKEYS_MEMBERS = 1000;
function objectToJSON(data) { function objectToJSON(data) {
return JSON.stringify(data); return JSON.stringify(data);
} }
@ -1145,6 +1147,31 @@ async function updateToLokiSchemaVersion14(currentVersion, instance) {
await instance.run('DROP TABLE IF EXISTS signedPreKeys;'); await instance.run('DROP TABLE IF EXISTS signedPreKeys;');
await instance.run('DROP TABLE IF EXISTS senderKeys;'); await instance.run('DROP TABLE IF EXISTS senderKeys;');
console.time('removingOpengroupv1Messages');
let toRemoveCount = 0;
do {
// eslint-disable-next-line no-await-in-loop
const row = await instance.get(`SELECT count(*) from ${MESSAGES_TABLE} WHERE
conversationId LIKE 'publicChat:1@%';`);
toRemoveCount = row['count(*)'];
if (toRemoveCount > 0) {
console.warn('toRemove count', toRemoveCount);
console.time('chunk');
// eslint-disable-next-line no-await-in-loop
await instance.all(
`DELETE FROM ${MESSAGES_TABLE} WHERE
conversationId LIKE 'publicChat:1@%'
;`
);
console.timeEnd('chunk');
}
} while (toRemoveCount > 0);
console.timeEnd('removingOpengroupv1Messages');
await instance.run( await instance.run(
`INSERT INTO loki_schema ( `INSERT INTO loki_schema (
version version
@ -1626,7 +1653,7 @@ async function getPubkeysInPublicConversation(id) {
const rows = await db.all( const rows = await db.all(
`SELECT DISTINCT source FROM ${MESSAGES_TABLE} WHERE `SELECT DISTINCT source FROM ${MESSAGES_TABLE} WHERE
conversationId = $conversationId conversationId = $conversationId
ORDER BY id ASC;`, ORDER BY received_at DESC LIMIT ${MAX_PUBKEYS_MEMBERS};`,
{ {
$conversationId: id, $conversationId: id,
} }
@ -2628,7 +2655,7 @@ async function createEncryptionKeyPairsForClosedGroup(instance) {
); );
} }
async function getAllClosedGroupConversations(instance) { async function getAllClosedGroupConversationsV1(instance) {
const rows = await (db || instance).all( const rows = await (db || instance).all(
`SELECT json FROM ${CONVERSATIONS_TABLE} WHERE `SELECT json FROM ${CONVERSATIONS_TABLE} WHERE
type = 'group' AND type = 'group' AND
@ -2648,7 +2675,7 @@ function remove05PrefixFromStringIfNeeded(str) {
async function updateExistingClosedGroupV1ToClosedGroupV2(instance) { async function updateExistingClosedGroupV1ToClosedGroupV2(instance) {
// the migration is called only once, so all current groups not being open groups are v1 closed group. // the migration is called only once, so all current groups not being open groups are v1 closed group.
const allClosedGroupV1 = (await getAllClosedGroupConversations(instance)) || []; const allClosedGroupV1 = (await getAllClosedGroupConversationsV1(instance)) || [];
await Promise.all( await Promise.all(
allClosedGroupV1.map(async groupV1 => { allClosedGroupV1.map(async groupV1 => {

@ -556,6 +556,9 @@ export async function getAllOpenGroupV1Conversations(): Promise<ConversationColl
return collection; return collection;
} }
/**
* This returns at most MAX_PUBKEYS_MEMBERS members, the last MAX_PUBKEYS_MEMBERS members who wrote in the chat
*/
export async function getPubkeysInPublicConversation(id: string): Promise<Array<string>> { export async function getPubkeysInPublicConversation(id: string): Promise<Array<string>> {
return channels.getPubkeysInPublicConversation(id); return channels.getPubkeysInPublicConversation(id);
} }

Loading…
Cancel
Save