Merge pull request #1792 from Bilb/disable-search-for-now

make removing open groups with a lot of messages way quicker
pull/1795/head
Audric Ackermann 4 years ago committed by GitHub
commit 1ae7a71afc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -354,7 +354,7 @@
"beginYourSession": "Begin<br />your<br />Session.", "beginYourSession": "Begin<br />your<br />Session.",
"welcomeToYourSession": "Welcome to your Session", "welcomeToYourSession": "Welcome to your Session",
"newSession": "New Session", "newSession": "New Session",
"searchFor...": "Search for conversations, contacts, and messages", "searchFor...": "Search for conversations or contacts",
"enterSessionID": "Enter Session ID", "enterSessionID": "Enter Session ID",
"enterSessionIDOfRecipient": "Enter Session ID or ONS name of recipient", "enterSessionIDOfRecipient": "Enter Session ID or ONS name of recipient",
"usersCanShareTheir...": "Users can share their Session ID by going into their account settings and tapping \"Share Session ID\", or by sharing their QR code.", "usersCanShareTheir...": "Users can share their Session ID by going into their account settings and tapping \"Share Session ID\", or by sharing their QR code.",

@ -41,7 +41,6 @@ module.exports = {
getAllOpenGroupV1Conversations, getAllOpenGroupV1Conversations,
getAllOpenGroupV2Conversations, getAllOpenGroupV2Conversations,
getPubkeysInPublicConversation, getPubkeysInPublicConversation,
getAllConversationIds,
getAllGroupsInvolvingId, getAllGroupsInvolvingId,
removeAllConversations, removeAllConversations,
@ -65,8 +64,6 @@ module.exports = {
getMessageBySenderAndServerTimestamp, getMessageBySenderAndServerTimestamp,
getMessageIdsFromServerIds, getMessageIdsFromServerIds,
getMessageById, getMessageById,
getAllMessages,
getAllMessageIds,
getMessagesBySentAt, getMessagesBySentAt,
getSeenMessagesByHashList, getSeenMessagesByHashList,
getLastHashBySnode, getLastHashBySnode,
@ -260,7 +257,7 @@ function openAndMigrateDatabase(filePath, key) {
switchToWAL(db2); switchToWAL(db2);
// Because foreign key support is not enabled by default! // Because foreign key support is not enabled by default!
db2.pragma('foreign_keys = ON'); db2.pragma('foreign_keys = OFF');
return db2; return db2;
} catch (error) { } catch (error) {
@ -834,6 +831,7 @@ const LOKI_SCHEMA_VERSIONS = [
updateToLokiSchemaVersion12, updateToLokiSchemaVersion12,
updateToLokiSchemaVersion13, updateToLokiSchemaVersion13,
updateToLokiSchemaVersion14, updateToLokiSchemaVersion14,
updateToLokiSchemaVersion15,
]; ];
function updateToLokiSchemaVersion1(currentVersion, db) { function updateToLokiSchemaVersion1(currentVersion, db) {
@ -1177,6 +1175,25 @@ function updateToLokiSchemaVersion14(currentVersion, db) {
console.log(`updateToLokiSchemaVersion${targetVersion}: success!`); console.log(`updateToLokiSchemaVersion${targetVersion}: success!`);
} }
function updateToLokiSchemaVersion15(currentVersion, db) {
const targetVersion = 15;
if (currentVersion >= targetVersion) {
return;
}
console.log(`updateToLokiSchemaVersion${targetVersion}: starting...`);
db.transaction(() => {
db.exec(`
DROP TABLE pairingAuthorisations;
DROP TRIGGER messages_on_delete;
DROP TRIGGER messages_on_update;
`);
writeLokiSchemaVersion(targetVersion, db);
})();
console.log(`updateToLokiSchemaVersion${targetVersion}: success!`);
}
function writeLokiSchemaVersion(newVersion, db) { function writeLokiSchemaVersion(newVersion, db) {
db.prepare( db.prepare(
`INSERT INTO loki_schema( `INSERT INTO loki_schema(
@ -1287,7 +1304,8 @@ function initialize({ configDir, key, messages, passwordAttempt }) {
// Clear any already deleted db entries on each app start. // Clear any already deleted db entries on each app start.
vacuumDatabase(db); vacuumDatabase(db);
getMessageCount(); const msgCount = getMessageCount();
console.warn('total message count: ', msgCount);
} catch (error) { } catch (error) {
if (passwordAttempt) { if (passwordAttempt) {
throw error; throw error;
@ -1612,13 +1630,6 @@ function getAllConversations() {
return map(rows, row => jsonToObject(row.json)); return map(rows, row => jsonToObject(row.json));
} }
function getAllConversationIds() {
const rows = globalInstance
.prepare(`SELECT id FROM ${CONVERSATIONS_TABLE} ORDER BY id ASC;`)
.all();
return map(rows, row => row.id);
}
function getAllOpenGroupV1Conversations() { function getAllOpenGroupV1Conversations() {
const rows = globalInstance const rows = globalInstance
.prepare( .prepare(
@ -1992,16 +2003,6 @@ function getMessageById(id) {
return jsonToObject(row.json); return jsonToObject(row.json);
} }
function getAllMessages() {
const rows = globalInstance.prepare(`SELECT json FROM ${MESSAGES_TABLE} ORDER BY id ASC;`).all();
return map(rows, row => jsonToObject(row.json));
}
function getAllMessageIds() {
const rows = globalInstance.prepare(`SELECT id FROM ${MESSAGES_TABLE} ORDER BY id ASC;`).all();
return map(rows, row => row.id);
}
function getMessageBySender({ source, sourceDevice, sentAt }) { function getMessageBySender({ source, sourceDevice, sentAt }) {
const rows = globalInstance const rows = globalInstance
.prepare( .prepare(

@ -54,7 +54,7 @@ export const SearchResults = (props: SearchResultsProps) => {
<ContactsItem header={window.i18n('contactsHeader')} items={contacts} /> <ContactsItem header={window.i18n('contactsHeader')} items={contacts} />
) : null} ) : null}
{haveMessages ? ( {/* {haveMessages ? (
<div className="module-search-results__messages"> <div className="module-search-results__messages">
{hideMessagesHeader ? null : ( {hideMessagesHeader ? null : (
<div className="module-search-results__messages-header"> <div className="module-search-results__messages-header">
@ -65,7 +65,7 @@ export const SearchResults = (props: SearchResultsProps) => {
<MessageSearchResult key={message.id} {...message} /> <MessageSearchResult key={message.id} {...message} />
))} ))}
</div> </div>
) : null} ) : null} */}
</div> </div>
); );
}; };

@ -5,6 +5,7 @@ import { SessionSearchInput } from './SessionSearchInput';
import { SearchResultsProps } from '../SearchResults'; import { SearchResultsProps } from '../SearchResults';
import { DefaultTheme } from 'styled-components'; import { DefaultTheme } from 'styled-components';
import autoBind from 'auto-bind';
export interface Props { export interface Props {
searchTerm: string; searchTerm: string;
@ -18,13 +19,9 @@ interface State {
} }
export class UserSearchDropdown extends React.Component<Props, State> { export class UserSearchDropdown extends React.Component<Props, State> {
private readonly updateSearchBound: (searchedString: string) => void;
public constructor(props: Props) { public constructor(props: Props) {
super(props); super(props);
this.updateSearchBound = this.updateSearch.bind(this); autoBind(this);
this.handleNavigation = this.handleNavigation.bind(this);
this.handleContactSelected = this.handleContactSelected.bind(this);
this.state = { this.state = {
selectedContact: -1, selectedContact: -1,
}; };
@ -64,7 +61,7 @@ export class UserSearchDropdown extends React.Component<Props, State> {
<div className="user-search-dropdown"> <div className="user-search-dropdown">
<SessionSearchInput <SessionSearchInput
searchString={this.props.searchTerm} searchString={this.props.searchTerm}
onChange={this.updateSearchBound} onChange={this.updateSearch}
placeholder={placeholder} placeholder={placeholder}
handleNavigation={this.handleNavigation} handleNavigation={this.handleNavigation}
/> />

@ -6,6 +6,7 @@ import _ from 'lodash';
import { contextMenu } from 'react-contexify'; import { contextMenu } from 'react-contexify';
import { import {
fetchMessagesForConversation, fetchMessagesForConversation,
markConversationFullyRead,
quotedMessageToAnimate, quotedMessageToAnimate,
ReduxConversationType, ReduxConversationType,
setNextMessageToPlay, setNextMessageToPlay,
@ -173,7 +174,9 @@ class SessionMessagesListContainerInner extends React.Component<Props> {
} }
if ((forceIsOnBottom || this.getScrollOffsetBottomPx() === 0) && isElectronWindowFocused()) { if ((forceIsOnBottom || this.getScrollOffsetBottomPx() === 0) && isElectronWindowFocused()) {
void conversation.markRead(messagesProps[0].propsForMessage.receivedAt || 0); void conversation.markRead(Date.now()).then(() => {
window.inboxStore?.dispatch(markConversationFullyRead(conversationKey));
});
} }
} }
@ -369,7 +372,9 @@ class SessionMessagesListContainerInner extends React.Component<Props> {
const conversation = getConversationController().get(conversationKey); const conversation = getConversationController().get(conversationKey);
if (isElectronWindowFocused()) { if (isElectronWindowFocused()) {
void conversation.markRead(messagesProps[0].propsForMessage.receivedAt || 0); void conversation.markRead(Date.now()).then(() => {
window.inboxStore?.dispatch(markConversationFullyRead(conversationKey));
});
} }
} }

@ -89,7 +89,6 @@ const channelsToMake = {
removeConversation, removeConversation,
getAllConversations, getAllConversations,
getAllConversationIds,
getAllOpenGroupV1Conversations, getAllOpenGroupV1Conversations,
getPubkeysInPublicConversation, getPubkeysInPublicConversation,
getAllGroupsInvolvingId, getAllGroupsInvolvingId,
@ -116,8 +115,6 @@ const channelsToMake = {
getMessageBySenderAndServerTimestamp, getMessageBySenderAndServerTimestamp,
getMessageIdsFromServerIds, getMessageIdsFromServerIds,
getMessageById, getMessageById,
getAllMessages,
getAllMessageIds,
getMessagesBySentAt, getMessagesBySentAt,
getExpiredMessages, getExpiredMessages,
getOutgoingWithoutExpiresAt, getOutgoingWithoutExpiresAt,
@ -541,11 +538,6 @@ export async function getAllConversations(): Promise<ConversationCollection> {
return collection; return collection;
} }
export async function getAllConversationIds(): Promise<Array<string>> {
const ids = await channels.getAllConversationIds();
return ids;
}
export async function getAllOpenGroupV1Conversations(): Promise<ConversationCollection> { export async function getAllOpenGroupV1Conversations(): Promise<ConversationCollection> {
const conversations = await channels.getAllOpenGroupV1Conversations(); const conversations = await channels.getAllOpenGroupV1Conversations();
@ -670,17 +662,6 @@ export async function getMessageById(
return new MessageModel(message); return new MessageModel(message);
} }
// For testing only
export async function getAllMessages(): Promise<MessageCollection> {
const messages = await channels.getAllMessages();
return new MessageCollection(messages);
}
export async function getAllMessageIds(): Promise<Array<string>> {
const ids = await channels.getAllMessageIds();
return ids;
}
export async function getMessageBySender({ export async function getMessageBySender({
source, source,
sourceDevice, sourceDevice,
@ -786,9 +767,8 @@ export async function removeAllMessagesInConversation(conversationId: string): P
// time so we don't use too much memory. // time so we don't use too much memory.
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
messages = await getMessagesByConversation(conversationId, { messages = await getMessagesByConversation(conversationId, {
limit: 100, limit: 500,
}); });
if (!messages.length) { if (!messages.length) {
return; return;
} }
@ -798,6 +778,7 @@ export async function removeAllMessagesInConversation(conversationId: string): P
// Note: It's very important that these models are fully hydrated because // Note: It's very important that these models are fully hydrated because
// we need to delete all associated on-disk files along with the database delete. // we need to delete all associated on-disk files along with the database delete.
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
await Promise.all(messages.map(message => message.cleanup())); await Promise.all(messages.map(message => message.cleanup()));
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop

@ -198,7 +198,10 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
}); });
this.throttledNotify = _.debounce(this.notify, 500, { maxWait: 1000, trailing: true }); this.throttledNotify = _.debounce(this.notify, 500, { maxWait: 1000, trailing: true });
//start right away the function is called, and wait 1sec before calling it again //start right away the function is called, and wait 1sec before calling it again
const markReadDebounced = _.debounce(this.markReadBouncy, 1000, { leading: true }); const markReadDebounced = _.debounce(this.markReadBouncy, 1000, {
leading: true,
trailing: true,
});
// tslint:disable-next-line: no-async-without-await // tslint:disable-next-line: no-async-without-await
this.markRead = async (newestUnreadDate: number) => { this.markRead = async (newestUnreadDate: number) => {
const lastReadTimestamp = this.lastReadTimestamp; const lastReadTimestamp = this.lastReadTimestamp;
@ -973,7 +976,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
let allUnreadMessagesInConvo = (await this.getUnread()).models; let allUnreadMessagesInConvo = (await this.getUnread()).models;
const oldUnreadNowRead = allUnreadMessagesInConvo.filter( const oldUnreadNowRead = allUnreadMessagesInConvo.filter(
(message: any) => message.get('received_at') <= newestUnreadDate message => (message.get('received_at') as number) <= newestUnreadDate
); );
let read = []; let read = [];

@ -601,6 +601,17 @@ const conversationsSlice = createSlice({
return handleConversationReset(state, action); return handleConversationReset(state, action);
}, },
markConversationFullyRead(state: ConversationsStateType, action: PayloadAction<string>) {
if (state.selectedConversation !== action.payload) {
return state;
}
return {
...state,
firstUnreadMessageId: undefined,
};
},
openConversationExternal( openConversationExternal(
state: ConversationsStateType, state: ConversationsStateType,
action: PayloadAction<{ action: PayloadAction<{
@ -711,6 +722,7 @@ export const {
messageChanged, messageChanged,
messagesChanged, messagesChanged,
openConversationExternal, openConversationExternal,
markConversationFullyRead,
// layout stuff // layout stuff
showMessageDetailsView, showMessageDetailsView,
closeMessageDetailsView, closeMessageDetailsView,

Loading…
Cancel
Save