Fixin linting errors.

pull/2139/head
warrickct 3 years ago
parent 804c9a56b9
commit 04241daa08

@ -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;

@ -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 }) => (
<AddNewLines key={key} text={text} />
);
@ -25,7 +21,7 @@ const renderEmoji = ({
renderNonEmoji: RenderTextCallbackType;
}) => <Emojify key={key} text={text} sizeClass={sizeClass} renderNonEmoji={renderNonEmoji} />;
export const MessageBodyHighlight = (props: Props) => {
export const MessageBodyHighlight = (props: { text: string }) => {
const { text } = props;
const results: Array<JSX.Element> = [];
const FIND_BEGIN_END = /<<left>>(.+?)<<right>>/g;

@ -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')}
/>
<SessionSettingButtonItem
{/* <SessionSettingButtonItem
title={window.i18n('trimDatabase')}
description={window.i18n('trimDatabaseDescription')}
onClick={async () => {
@ -160,7 +156,7 @@ export const SettingsCategoryAppearance = (props: { hasPassword: boolean | null
}}
buttonColor={SessionButtonColor.Primary}
buttonText={window.i18n('trimDatabase')}
/>
/> */}
<SessionSettingButtonItem
onClick={() => {
ipcRenderer.send('show-debug-log');
@ -170,14 +166,7 @@ export const SettingsCategoryAppearance = (props: { hasPassword: boolean | null
/>
<SessionSettingButtonItem
onClick={async () => {
await fillWithTestData(100, 2000000);
}}
buttonColor={SessionButtonColor.Primary}
buttonText={'Spam fill DB'}
/>
<SessionSettingButtonItem
onClick={async () => {
await fillWithTestData2(100, 1000);
await fillWithTestData(100, 1000);
}}
buttonColor={SessionButtonColor.Primary}
buttonText={'Spam fill DB using cached'}

@ -995,22 +995,7 @@ export async function removeOneOpenGroupV1Message(): Promise<number> {
* @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<void> {
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',
});
}
};
}

Loading…
Cancel
Save