From 04241daa08f95dcf558f2c89b78a7487ae424e4a Mon Sep 17 00:00:00 2001 From: warrickct Date: Mon, 17 Jan 2022 16:16:59 +1100 Subject: [PATCH] Fixin linting errors. --- app/sql.js | 93 ++++++++----------- ts/components/basic/MessageBodyHighlight.tsx | 6 +- .../settings/section/CategoryAppearance.tsx | 17 +--- ts/data/data.ts | 19 +--- 4 files changed, 45 insertions(+), 90 deletions(-) diff --git a/app/sql.js b/app/sql.js index 3fbeb135f..4cc7259b0 100644 --- a/app/sql.js +++ b/app/sql.js @@ -7,7 +7,6 @@ const { redactAll } = require('../js/modules/privacy'); const { remove: removeUserConfig } = require('./user_config'); const { map, isString, fromPairs, forEach, last, isEmpty, isObject, isNumber } = require('lodash'); -const { requestSnodesForPubkey } = require('../ts/session/apis/snode_api/SNodeAPI'); /* eslint-disable camelcase */ @@ -2285,6 +2284,7 @@ function getFirstUnreadMessageIdInConversation(conversationId) { * Deletes all but the 10,000 last received messages. */ function trimMessages(limit) { + console.log(limit); // adding this for linting purposes. // METHOD 1 Start - Seems to take to long and freeze // const convoCount = globalInstance // .prepare( @@ -2296,14 +2296,12 @@ function trimMessages(limit) { // .all({ // conversationId, // }); - // if (convoCount < limit) { // console.log(`Skipping conversation: ${conversationId}`); // return; // } else { // console.count('convo surpassed limit'); // } - // globalInstance // .prepare( // ` @@ -2321,58 +2319,48 @@ function trimMessages(limit) { // conversationId, // limit, // }); - // METHOD 1 END - // METHOD 2 Start - const messages = globalInstance - .prepare( - ` - SELECT id, conversationId FROM ${MESSAGES_TABLE} - - CREATE VIRTUAL TABLE IF NOT EXISTS temp_deletion - id STRING PRIMARY KEY ASC - ` - ) - .all(); - - let idsToDelete = []; - const convoCountLookup = {}; - - for (let index = 0; index < messages.length; index++) { - const { conversationId, id } = messages[index]; - console.log(`run ${index} - convoId: ${conversationId}, messageId: ${id}`); - - if (!convoCountLookup[conversationId]) { - convoCountLookup[conversationId] = 1; - } else { - convoCountLookup[conversationId]++; - if (convoCountLookup[conversationId] > limit) { - idsToDelete.push(id); - } - } - } - - // Ideally should be able to do WHERE id IN (x, y, z) with an array of IDs - // the array might need to be chunked as well for performance - const idSlice = [...idsToDelete].slice(0, 30); - idSlice.forEach(id => { - globalInstance - .prepare( - ` - DELETE FROM ${MESSAGES_TABLE} - WHERE id = $idSlice - ` - ) - .run({ - idSlice, - }); - }); - + // const messages = globalInstance + // .prepare( + // ` + // SELECT id, conversationId FROM ${MESSAGES_TABLE} + // CREATE VIRTUAL TABLE IF NOT EXISTS temp_deletion + // id STRING PRIMARY KEY ASC + // ` + // ) + // .all(); + // const idsToDelete = []; + // const convoCountLookup = {}; + // for (let index = 0; index < messages.length; index + 1) { + // const { conversationId, id } = messages[index]; + // console.log(`run ${index} - convoId: ${conversationId}, messageId: ${id}`); + // if (!convoCountLookup[conversationId]) { + // convoCountLookup[conversationId] = 1; + // } else { + // convoCountLookup[conversationId] + 1; + // if (convoCountLookup[conversationId] > limit) { + // idsToDelete.push(id); + // } + // } + // } + // // Ideally should be able to do WHERE id IN (x, y, z) with an array of IDs + // // the array might need to be chunked as well for performance + // const idSlice = [...idsToDelete].slice(0, 30); + // idSlice.forEach(() => { + // globalInstance + // .prepare( + // ` + // DELETE FROM ${MESSAGES_TABLE} + // WHERE id = $idSlice + // ` + // ) + // .run({ + // idSlice, + // }); + // }); // Method 2 End - // Method 3 start - Audric's suggestion - // const largeConvos = globalInstance // .prepare( // ` @@ -2382,9 +2370,7 @@ function trimMessages(limit) { // ` // ) // .all(); - // console.log({ largeConvos }); - // // finding 1000th msg timestamp // largeConvos.forEach(convo => { // const convoId = convo.conversationId; @@ -2402,7 +2388,6 @@ function trimMessages(limit) { // .all({ // convoId, // }); - // // use timestamp with lesserThan as conditional for deletion // console.log({ lastMsg }); // const timestamp = lastMsg[0].received_at; diff --git a/ts/components/basic/MessageBodyHighlight.tsx b/ts/components/basic/MessageBodyHighlight.tsx index f0948c316..64bedfeb9 100644 --- a/ts/components/basic/MessageBodyHighlight.tsx +++ b/ts/components/basic/MessageBodyHighlight.tsx @@ -5,10 +5,6 @@ import { AddNewLines } from '../conversation/AddNewLines'; import { Emojify } from '../conversation/Emojify'; import { MessageBody } from '../conversation/message/message-content/MessageBody'; -interface Props { - text: string; -} - const renderNewLines: RenderTextCallbackType = ({ text, key }) => ( ); @@ -25,7 +21,7 @@ const renderEmoji = ({ renderNonEmoji: RenderTextCallbackType; }) => ; -export const MessageBodyHighlight = (props: Props) => { +export const MessageBodyHighlight = (props: { text: string }) => { const { text } = props; const results: Array = []; const FIND_BEGIN_END = /<>(.+?)<>/g; diff --git a/ts/components/settings/section/CategoryAppearance.tsx b/ts/components/settings/section/CategoryAppearance.tsx index 66c421726..2f0afba7d 100644 --- a/ts/components/settings/section/CategoryAppearance.tsx +++ b/ts/components/settings/section/CategoryAppearance.tsx @@ -6,11 +6,7 @@ import useUpdate from 'react-use/lib/useUpdate'; import { createOrUpdateItem, fillWithTestData, - fillWithTestData2, - // fillWithTestData2, - getMessageCount, hasLinkPreviewPopupBeenDisplayed, - trimMessages, } from '../../../data/data'; import { ToastUtils } from '../../../session/utils'; import { updateConfirmModal } from '../../../state/ducks/modalDialog'; @@ -139,7 +135,7 @@ export const SettingsCategoryAppearance = (props: { hasPassword: boolean | null buttonColor={SessionButtonColor.Primary} buttonText={window.i18n('translation')} /> - { @@ -160,7 +156,7 @@ export const SettingsCategoryAppearance = (props: { hasPassword: boolean | null }} buttonColor={SessionButtonColor.Primary} buttonText={window.i18n('trimDatabase')} - /> + /> */} { ipcRenderer.send('show-debug-log'); @@ -170,14 +166,7 @@ export const SettingsCategoryAppearance = (props: { hasPassword: boolean | null /> { - await fillWithTestData(100, 2000000); - }} - buttonColor={SessionButtonColor.Primary} - buttonText={'Spam fill DB'} - /> - { - await fillWithTestData2(100, 1000); + await fillWithTestData(100, 1000); }} buttonColor={SessionButtonColor.Primary} buttonText={'Spam fill DB using cached'} diff --git a/ts/data/data.ts b/ts/data/data.ts index 60e3ab467..68244b9e2 100644 --- a/ts/data/data.ts +++ b/ts/data/data.ts @@ -995,22 +995,7 @@ export async function removeOneOpenGroupV1Message(): Promise { * @param numConvosToAdd Amount of fake conversations to generate * @param numMsgsToAdd Number of fake messages to generate */ -export async function fillWithTestData( - numConvosToAdd: number, - numMsgsToAdd: number -): Promise { - if (!channels.fillWithTestData) { - return; - } - const ids = await channels.fillWithTestData(numConvosToAdd, numMsgsToAdd); - ids.map((id: string) => { - const convo = getConversationController().get(id); - const convoMsg = 'x'; - convo.set('lastMessage', convoMsg); - }); -} - -export const fillWithTestData2 = async (convs: number, msgs: number) => { +export async function fillWithTestData(convs: number, msgs: number) { const newConvos = []; for (let convsAddedCount = 0; convsAddedCount < convs; convsAddedCount++) { const convoId = `${Date.now()} + ${convsAddedCount}`; @@ -1036,4 +1021,4 @@ export const fillWithTestData2 = async (convs: number, msgs: number) => { direction: Math.random() > 0.5 ? 'outgoing' : 'incoming', }); } -}; +}