|
|
|
@ -351,9 +351,7 @@ function getById(table: string, id: string, instance?: BetterSqlite3.Database) {
|
|
|
|
|
|
|
|
|
|
function removeById(table: string, id: string) {
|
|
|
|
|
if (!Array.isArray(id)) {
|
|
|
|
|
assertGlobalInstance()
|
|
|
|
|
.prepare(`DELETE FROM ${table} WHERE id = $id;`)
|
|
|
|
|
.run({ id });
|
|
|
|
|
assertGlobalInstance().prepare(`DELETE FROM ${table} WHERE id = $id;`).run({ id });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -401,9 +399,7 @@ function updateSwarmNodesForPubkey(pubkey: string, snodeEdKeys: Array<string>) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getConversationCount() {
|
|
|
|
|
const row = assertGlobalInstance()
|
|
|
|
|
.prepare(`SELECT count(*) from ${CONVERSATIONS_TABLE};`)
|
|
|
|
|
.get();
|
|
|
|
|
const row = assertGlobalInstance().prepare(`SELECT count(*) from ${CONVERSATIONS_TABLE};`).get();
|
|
|
|
|
if (!row) {
|
|
|
|
|
throw new Error(`getConversationCount: Unable to get count of ${CONVERSATIONS_TABLE}`);
|
|
|
|
|
}
|
|
|
|
@ -530,9 +526,7 @@ function fetchConvoMemoryDetails(convoId: string): SaveConversationReturn {
|
|
|
|
|
|
|
|
|
|
function removeConversation(id: string | Array<string>) {
|
|
|
|
|
if (!Array.isArray(id)) {
|
|
|
|
|
assertGlobalInstance()
|
|
|
|
|
.prepare(`DELETE FROM ${CONVERSATIONS_TABLE} WHERE id = $id;`)
|
|
|
|
|
.run({
|
|
|
|
|
assertGlobalInstance().prepare(`DELETE FROM ${CONVERSATIONS_TABLE} WHERE id = $id;`).run({
|
|
|
|
|
id,
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
@ -778,9 +772,7 @@ function searchMessagesInConversation(query: string, conversationId: string, lim
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getMessageCount() {
|
|
|
|
|
const row = assertGlobalInstance()
|
|
|
|
|
.prepare(`SELECT count(*) from ${MESSAGES_TABLE};`)
|
|
|
|
|
.get();
|
|
|
|
|
const row = assertGlobalInstance().prepare(`SELECT count(*) from ${MESSAGES_TABLE};`).get();
|
|
|
|
|
|
|
|
|
|
if (!row) {
|
|
|
|
|
throw new Error(`getMessageCount: Unable to get count of ${MESSAGES_TABLE}`);
|
|
|
|
@ -953,17 +945,13 @@ function saveSeenMessageHash(data: any) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function cleanLastHashes() {
|
|
|
|
|
assertGlobalInstance()
|
|
|
|
|
.prepare(`DELETE FROM ${LAST_HASHES_TABLE} WHERE expiresAt <= $now;`)
|
|
|
|
|
.run({
|
|
|
|
|
assertGlobalInstance().prepare(`DELETE FROM ${LAST_HASHES_TABLE} WHERE expiresAt <= $now;`).run({
|
|
|
|
|
now: Date.now(),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function cleanSeenMessages() {
|
|
|
|
|
assertGlobalInstance()
|
|
|
|
|
.prepare('DELETE FROM seenMessages WHERE expiresAt <= $now;')
|
|
|
|
|
.run({
|
|
|
|
|
assertGlobalInstance().prepare('DELETE FROM seenMessages WHERE expiresAt <= $now;').run({
|
|
|
|
|
now: Date.now(),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -1738,9 +1726,7 @@ const unprocessed: UnprocessedDataNode = {
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getUnprocessedById: (id: string) => {
|
|
|
|
|
const row = assertGlobalInstance()
|
|
|
|
|
.prepare('SELECT * FROM unprocessed WHERE id = $id;')
|
|
|
|
|
.get({
|
|
|
|
|
const row = assertGlobalInstance().prepare('SELECT * FROM unprocessed WHERE id = $id;').get({
|
|
|
|
|
id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -1748,9 +1734,7 @@ const unprocessed: UnprocessedDataNode = {
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getUnprocessedCount: () => {
|
|
|
|
|
const row = assertGlobalInstance()
|
|
|
|
|
.prepare('SELECT count(*) from unprocessed;')
|
|
|
|
|
.get();
|
|
|
|
|
const row = assertGlobalInstance().prepare('SELECT count(*) from unprocessed;').get();
|
|
|
|
|
|
|
|
|
|
if (!row) {
|
|
|
|
|
throw new Error('getMessageCount: Unable to get count of unprocessed');
|
|
|
|
@ -1772,15 +1756,11 @@ const unprocessed: UnprocessedDataNode = {
|
|
|
|
|
console.error('removeUnprocessed only supports single ids at a time');
|
|
|
|
|
throw new Error('removeUnprocessed only supports single ids at a time');
|
|
|
|
|
}
|
|
|
|
|
assertGlobalInstance()
|
|
|
|
|
.prepare('DELETE FROM unprocessed WHERE id = $id;')
|
|
|
|
|
.run({ id });
|
|
|
|
|
assertGlobalInstance().prepare('DELETE FROM unprocessed WHERE id = $id;').run({ id });
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
removeAllUnprocessed: () => {
|
|
|
|
|
assertGlobalInstance()
|
|
|
|
|
.prepare('DELETE FROM unprocessed;')
|
|
|
|
|
.run();
|
|
|
|
|
assertGlobalInstance().prepare('DELETE FROM unprocessed;').run();
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -1870,9 +1850,7 @@ function removeAll() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function removeAllConversations() {
|
|
|
|
|
assertGlobalInstance()
|
|
|
|
|
.prepare(`DELETE FROM ${CONVERSATIONS_TABLE};`)
|
|
|
|
|
.run();
|
|
|
|
|
assertGlobalInstance().prepare(`DELETE FROM ${CONVERSATIONS_TABLE};`).run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getMessagesWithVisualMediaAttachments(conversationId: string, limit?: number) {
|
|
|
|
@ -2220,9 +2198,7 @@ function removeV2OpenGroupRoom(conversationId: string) {
|
|
|
|
|
|
|
|
|
|
function getEntriesCountInTable(tbl: string) {
|
|
|
|
|
try {
|
|
|
|
|
const row = assertGlobalInstance()
|
|
|
|
|
.prepare(`SELECT count(*) from ${tbl};`)
|
|
|
|
|
.get();
|
|
|
|
|
const row = assertGlobalInstance().prepare(`SELECT count(*) from ${tbl};`).get();
|
|
|
|
|
return row['count(*)'];
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
@ -2387,8 +2363,9 @@ function cleanUpOldOpengroupsOnStart() {
|
|
|
|
|
const messagesInConvoAfter = getMessagesCountByConversation(convoId);
|
|
|
|
|
|
|
|
|
|
console.info(
|
|
|
|
|
`Cleaning ${countToRemove} messages older than 6 months in public convo: ${convoId} took ${Date.now() -
|
|
|
|
|
start}ms. Old message count: ${messagesInConvoBefore}, new message count: ${messagesInConvoAfter}`
|
|
|
|
|
`Cleaning ${countToRemove} messages older than 6 months in public convo: ${convoId} took ${
|
|
|
|
|
Date.now() - start
|
|
|
|
|
}ms. Old message count: ${messagesInConvoBefore}, new message count: ${messagesInConvoAfter}`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// no need to update the `unreadCount` during the migration anymore.
|
|
|
|
|