Optimize updating call unread count
This commit is contained in:
parent
67252866cf
commit
c901708281
4 changed files with 48 additions and 5 deletions
|
@ -3624,7 +3624,7 @@ const FOUR_HOURS_IN_MS = sqlConstant(4 * 60 * 60 * 1000);
|
|||
function getCallHistoryUnreadCount(db: ReadableDB): number {
|
||||
const [query, params] = sql`
|
||||
SELECT count(*) FROM messages
|
||||
LEFT JOIN callsHistory ON callsHistory.callId = messages.callId
|
||||
INNER JOIN callsHistory ON callsHistory.callId = messages.callId
|
||||
WHERE messages.type IS 'call-history'
|
||||
AND messages.seenStatus IS ${SEEN_STATUS_UNSEEN}
|
||||
AND callsHistory.status IS ${CALL_STATUS_MISSED}
|
||||
|
|
36
ts/sql/migrations/1160-optimize-calls-unread-count.ts
Normal file
36
ts/sql/migrations/1160-optimize-calls-unread-count.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Copyright 2024 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import type { LoggerType } from '../../types/Logging';
|
||||
import { sql, sqlConstant } from '../util';
|
||||
import { CallDirection, CallStatusValue } from '../../types/CallDisposition';
|
||||
|
||||
export const version = 1160;
|
||||
|
||||
const CALL_STATUS_MISSED = sqlConstant(CallStatusValue.Missed);
|
||||
const CALL_DIRECTION_INCOMING = sqlConstant(CallDirection.Incoming);
|
||||
|
||||
export function updateToSchemaVersion1160(
|
||||
currentVersion: number,
|
||||
db: Database,
|
||||
logger: LoggerType
|
||||
): void {
|
||||
if (currentVersion >= 1160) {
|
||||
return;
|
||||
}
|
||||
|
||||
db.transaction(() => {
|
||||
const [query] = sql`
|
||||
DROP INDEX IF EXISTS callsHistory_incoming_missed;
|
||||
|
||||
CREATE INDEX callsHistory_incoming_missed
|
||||
ON callsHistory (callId, status, direction)
|
||||
WHERE status IS ${CALL_STATUS_MISSED}
|
||||
AND direction IS ${CALL_DIRECTION_INCOMING};
|
||||
`;
|
||||
db.exec(query);
|
||||
|
||||
db.pragma('user_version = 1160');
|
||||
})();
|
||||
logger.info('updateToSchemaVersion1160: success!');
|
||||
}
|
|
@ -91,10 +91,11 @@ import { updateToSchemaVersion1110 } from './1110-sticker-local-key';
|
|||
import { updateToSchemaVersion1120 } from './1120-messages-foreign-keys-indexes';
|
||||
import { updateToSchemaVersion1130 } from './1130-isStory-index';
|
||||
import { updateToSchemaVersion1140 } from './1140-call-links-deleted-column';
|
||||
import { updateToSchemaVersion1150 } from './1150-expire-timer-version';
|
||||
import {
|
||||
updateToSchemaVersion1150,
|
||||
updateToSchemaVersion1160,
|
||||
version as MAX_VERSION,
|
||||
} from './1150-expire-timer-version';
|
||||
} from './1160-optimize-calls-unread-count';
|
||||
|
||||
function updateToSchemaVersion1(
|
||||
currentVersion: number,
|
||||
|
@ -2054,6 +2055,7 @@ export const SCHEMA_VERSIONS = [
|
|||
updateToSchemaVersion1130,
|
||||
updateToSchemaVersion1140,
|
||||
updateToSchemaVersion1150,
|
||||
updateToSchemaVersion1160,
|
||||
];
|
||||
|
||||
export class DBVersionFromFutureError extends Error {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
import type { ReadonlyDeep } from 'type-fest';
|
||||
import type { ThunkAction } from 'redux-thunk';
|
||||
import { omit } from 'lodash';
|
||||
import { debounce, omit } from 'lodash';
|
||||
import type { StateType as RootStateType } from '../reducer';
|
||||
import {
|
||||
clearCallHistoryDataAndSync,
|
||||
|
@ -86,7 +86,7 @@ export function getEmptyState(): CallHistoryState {
|
|||
};
|
||||
}
|
||||
|
||||
function updateCallHistoryUnreadCount(): ThunkAction<
|
||||
function updateCallHistoryUnreadCountInner(): ThunkAction<
|
||||
void,
|
||||
RootStateType,
|
||||
unknown,
|
||||
|
@ -105,6 +105,11 @@ function updateCallHistoryUnreadCount(): ThunkAction<
|
|||
};
|
||||
}
|
||||
|
||||
const updateCallHistoryUnreadCount = debounce(
|
||||
updateCallHistoryUnreadCountInner,
|
||||
300
|
||||
);
|
||||
|
||||
function markCallHistoryRead(
|
||||
conversationId: string,
|
||||
callId: string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue