loadAndScroll: Use one transaction to pull all data: old/new/metrics
This commit is contained in:
parent
60a53656af
commit
0163ef203b
4 changed files with 132 additions and 16 deletions
|
@ -121,6 +121,7 @@ const {
|
||||||
} = window.Signal.Migrations;
|
} = window.Signal.Migrations;
|
||||||
const {
|
const {
|
||||||
addStickerPackReference,
|
addStickerPackReference,
|
||||||
|
getConversationRangeCenteredOnMessage,
|
||||||
getOlderMessagesByConversation,
|
getOlderMessagesByConversation,
|
||||||
getMessageMetricsForConversation,
|
getMessageMetricsForConversation,
|
||||||
getMessageById,
|
getMessageById,
|
||||||
|
@ -1576,19 +1577,14 @@ export class ConversationModel extends window.Backbone
|
||||||
|
|
||||||
const receivedAt = message.received_at;
|
const receivedAt = message.received_at;
|
||||||
const sentAt = message.sent_at;
|
const sentAt = message.sent_at;
|
||||||
const older = await getOlderMessagesByConversation(conversationId, {
|
const { older, newer, metrics } =
|
||||||
|
await getConversationRangeCenteredOnMessage({
|
||||||
|
conversationId,
|
||||||
limit: MESSAGE_LOAD_CHUNK_SIZE,
|
limit: MESSAGE_LOAD_CHUNK_SIZE,
|
||||||
receivedAt,
|
receivedAt,
|
||||||
sentAt,
|
sentAt,
|
||||||
messageId,
|
messageId,
|
||||||
});
|
});
|
||||||
const newer = await getNewerMessagesByConversation(conversationId, {
|
|
||||||
limit: MESSAGE_LOAD_CHUNK_SIZE,
|
|
||||||
receivedAt,
|
|
||||||
sentAt,
|
|
||||||
});
|
|
||||||
const metrics = await getMessageMetricsForConversation(conversationId);
|
|
||||||
|
|
||||||
const all = [...older, message, ...newer];
|
const all = [...older, message, ...newer];
|
||||||
|
|
||||||
const cleaned: Array<MessageModel> = await this.cleanModels(all);
|
const cleaned: Array<MessageModel> = await this.cleanModels(all);
|
||||||
|
|
|
@ -240,6 +240,7 @@ const dataInterface: ClientInterface = {
|
||||||
getOlderStories,
|
getOlderStories,
|
||||||
getNewerMessagesByConversation,
|
getNewerMessagesByConversation,
|
||||||
getMessageMetricsForConversation,
|
getMessageMetricsForConversation,
|
||||||
|
getConversationRangeCenteredOnMessage,
|
||||||
getLastConversationMessages,
|
getLastConversationMessages,
|
||||||
hasGroupCallHistoryMessage,
|
hasGroupCallHistoryMessage,
|
||||||
migrateConversationMessages,
|
migrateConversationMessages,
|
||||||
|
@ -1318,6 +1319,23 @@ async function getMessageMetricsForConversation(
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
async function getConversationRangeCenteredOnMessage(options: {
|
||||||
|
conversationId: string;
|
||||||
|
limit?: number;
|
||||||
|
messageId: string;
|
||||||
|
receivedAt: number;
|
||||||
|
sentAt?: number;
|
||||||
|
storyId?: UUIDStringType;
|
||||||
|
}) {
|
||||||
|
const result = await channels.getConversationRangeCenteredOnMessage(options);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
older: handleMessageJSON(result.older),
|
||||||
|
newer: handleMessageJSON(result.newer),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function hasGroupCallHistoryMessage(
|
function hasGroupCallHistoryMessage(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
eraId: string
|
eraId: string
|
||||||
|
|
|
@ -451,6 +451,7 @@ export type DataInterface = {
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
storyId?: UUIDStringType
|
storyId?: UUIDStringType
|
||||||
) => Promise<ConversationMetricsType>;
|
) => Promise<ConversationMetricsType>;
|
||||||
|
// getConversationRangeCenteredOnMessage is JSON on server, full message on client
|
||||||
getLastConversationMessages: (options: {
|
getLastConversationMessages: (options: {
|
||||||
conversationId: string;
|
conversationId: string;
|
||||||
ourUuid: UUIDStringType;
|
ourUuid: UUIDStringType;
|
||||||
|
@ -622,6 +623,18 @@ export type ServerInterface = DataInterface & {
|
||||||
storyId?: UUIDStringType;
|
storyId?: UUIDStringType;
|
||||||
}
|
}
|
||||||
) => Promise<Array<MessageTypeUnhydrated>>;
|
) => Promise<Array<MessageTypeUnhydrated>>;
|
||||||
|
getConversationRangeCenteredOnMessage: (options: {
|
||||||
|
conversationId: string;
|
||||||
|
limit?: number;
|
||||||
|
messageId: string;
|
||||||
|
receivedAt: number;
|
||||||
|
sentAt?: number;
|
||||||
|
storyId?: UUIDStringType;
|
||||||
|
}) => Promise<{
|
||||||
|
older: Array<MessageTypeUnhydrated>;
|
||||||
|
newer: Array<MessageTypeUnhydrated>;
|
||||||
|
metrics: ConversationMetricsType;
|
||||||
|
}>;
|
||||||
|
|
||||||
// Server-only
|
// Server-only
|
||||||
|
|
||||||
|
@ -681,6 +694,18 @@ export type ClientInterface = DataInterface & {
|
||||||
storyId?: UUIDStringType;
|
storyId?: UUIDStringType;
|
||||||
}
|
}
|
||||||
) => Promise<Array<MessageAttributesType>>;
|
) => Promise<Array<MessageAttributesType>>;
|
||||||
|
getConversationRangeCenteredOnMessage: (options: {
|
||||||
|
conversationId: string;
|
||||||
|
limit?: number;
|
||||||
|
messageId: string;
|
||||||
|
receivedAt: number;
|
||||||
|
sentAt?: number;
|
||||||
|
storyId?: UUIDStringType;
|
||||||
|
}) => Promise<{
|
||||||
|
older: Array<MessageAttributesType>;
|
||||||
|
newer: Array<MessageAttributesType>;
|
||||||
|
metrics: ConversationMetricsType;
|
||||||
|
}>;
|
||||||
|
|
||||||
// Client-side only
|
// Client-side only
|
||||||
|
|
||||||
|
|
|
@ -236,6 +236,7 @@ const dataInterface: ServerInterface = {
|
||||||
getNewerMessagesByConversation,
|
getNewerMessagesByConversation,
|
||||||
getTotalUnreadForConversation,
|
getTotalUnreadForConversation,
|
||||||
getMessageMetricsForConversation,
|
getMessageMetricsForConversation,
|
||||||
|
getConversationRangeCenteredOnMessage,
|
||||||
getLastConversationMessages,
|
getLastConversationMessages,
|
||||||
hasGroupCallHistoryMessage,
|
hasGroupCallHistoryMessage,
|
||||||
migrateConversationMessages,
|
migrateConversationMessages,
|
||||||
|
@ -2304,6 +2305,18 @@ async function _removeAllReactions(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getOlderMessagesByConversation(
|
async function getOlderMessagesByConversation(
|
||||||
|
conversationId: string,
|
||||||
|
options?: {
|
||||||
|
limit?: number;
|
||||||
|
messageId?: string;
|
||||||
|
receivedAt?: number;
|
||||||
|
sentAt?: number;
|
||||||
|
storyId?: UUIDStringType;
|
||||||
|
}
|
||||||
|
): Promise<Array<MessageTypeUnhydrated>> {
|
||||||
|
return getOlderMessagesByConversationSync(conversationId, options);
|
||||||
|
}
|
||||||
|
function getOlderMessagesByConversationSync(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
{
|
{
|
||||||
limit = 100,
|
limit = 100,
|
||||||
|
@ -2318,7 +2331,7 @@ async function getOlderMessagesByConversation(
|
||||||
sentAt?: number;
|
sentAt?: number;
|
||||||
storyId?: UUIDStringType;
|
storyId?: UUIDStringType;
|
||||||
} = {}
|
} = {}
|
||||||
): Promise<Array<MessageTypeUnhydrated>> {
|
): Array<MessageTypeUnhydrated> {
|
||||||
const db = getInstance();
|
const db = getInstance();
|
||||||
|
|
||||||
return db
|
return db
|
||||||
|
@ -2390,6 +2403,17 @@ async function getOlderStories({
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getNewerMessagesByConversation(
|
async function getNewerMessagesByConversation(
|
||||||
|
conversationId: string,
|
||||||
|
options?: {
|
||||||
|
limit?: number;
|
||||||
|
receivedAt?: number;
|
||||||
|
sentAt?: number;
|
||||||
|
storyId?: UUIDStringType;
|
||||||
|
}
|
||||||
|
): Promise<Array<MessageTypeUnhydrated>> {
|
||||||
|
return getNewerMessagesByConversationSync(conversationId, options);
|
||||||
|
}
|
||||||
|
function getNewerMessagesByConversationSync(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
{
|
{
|
||||||
limit = 100,
|
limit = 100,
|
||||||
|
@ -2402,7 +2426,7 @@ async function getNewerMessagesByConversation(
|
||||||
sentAt?: number;
|
sentAt?: number;
|
||||||
storyId?: UUIDStringType;
|
storyId?: UUIDStringType;
|
||||||
} = {}
|
} = {}
|
||||||
): Promise<Array<MessageTypeUnhydrated>> {
|
): Array<MessageTypeUnhydrated> {
|
||||||
const db = getInstance();
|
const db = getInstance();
|
||||||
const rows: JSONRows = db
|
const rows: JSONRows = db
|
||||||
.prepare<Query>(
|
.prepare<Query>(
|
||||||
|
@ -2609,6 +2633,12 @@ async function getTotalUnreadForConversation(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
storyId?: UUIDStringType
|
storyId?: UUIDStringType
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
|
return getTotalUnreadForConversationSync(conversationId, storyId);
|
||||||
|
}
|
||||||
|
function getTotalUnreadForConversationSync(
|
||||||
|
conversationId: string,
|
||||||
|
storyId?: UUIDStringType
|
||||||
|
): number {
|
||||||
const db = getInstance();
|
const db = getInstance();
|
||||||
const row = db
|
const row = db
|
||||||
.prepare<Query>(
|
.prepare<Query>(
|
||||||
|
@ -2638,13 +2668,19 @@ async function getMessageMetricsForConversation(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
storyId?: UUIDStringType
|
storyId?: UUIDStringType
|
||||||
): Promise<ConversationMetricsType> {
|
): Promise<ConversationMetricsType> {
|
||||||
|
return getMessageMetricsForConversationSync(conversationId, storyId);
|
||||||
|
}
|
||||||
|
function getMessageMetricsForConversationSync(
|
||||||
|
conversationId: string,
|
||||||
|
storyId?: UUIDStringType
|
||||||
|
): ConversationMetricsType {
|
||||||
const oldest = getOldestMessageForConversation(conversationId, storyId);
|
const oldest = getOldestMessageForConversation(conversationId, storyId);
|
||||||
const newest = getNewestMessageForConversation(conversationId, storyId);
|
const newest = getNewestMessageForConversation(conversationId, storyId);
|
||||||
const oldestUnread = getOldestUnreadMessageForConversation(
|
const oldestUnread = getOldestUnreadMessageForConversation(
|
||||||
conversationId,
|
conversationId,
|
||||||
storyId
|
storyId
|
||||||
);
|
);
|
||||||
const totalUnread = await getTotalUnreadForConversation(
|
const totalUnread = getTotalUnreadForConversationSync(
|
||||||
conversationId,
|
conversationId,
|
||||||
storyId
|
storyId
|
||||||
);
|
);
|
||||||
|
@ -2659,6 +2695,47 @@ async function getMessageMetricsForConversation(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getConversationRangeCenteredOnMessage({
|
||||||
|
conversationId,
|
||||||
|
limit,
|
||||||
|
messageId,
|
||||||
|
receivedAt,
|
||||||
|
sentAt,
|
||||||
|
storyId,
|
||||||
|
}: {
|
||||||
|
conversationId: string;
|
||||||
|
limit?: number;
|
||||||
|
messageId: string;
|
||||||
|
receivedAt: number;
|
||||||
|
sentAt?: number;
|
||||||
|
storyId?: UUIDStringType;
|
||||||
|
}): Promise<{
|
||||||
|
older: Array<MessageTypeUnhydrated>;
|
||||||
|
newer: Array<MessageTypeUnhydrated>;
|
||||||
|
metrics: ConversationMetricsType;
|
||||||
|
}> {
|
||||||
|
const db = getInstance();
|
||||||
|
|
||||||
|
return db.transaction(() => {
|
||||||
|
return {
|
||||||
|
older: getOlderMessagesByConversationSync(conversationId, {
|
||||||
|
limit,
|
||||||
|
messageId,
|
||||||
|
receivedAt,
|
||||||
|
sentAt,
|
||||||
|
storyId,
|
||||||
|
}),
|
||||||
|
newer: getNewerMessagesByConversationSync(conversationId, {
|
||||||
|
limit,
|
||||||
|
receivedAt,
|
||||||
|
sentAt,
|
||||||
|
storyId,
|
||||||
|
}),
|
||||||
|
metrics: getMessageMetricsForConversationSync(conversationId, storyId),
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
async function hasGroupCallHistoryMessage(
|
async function hasGroupCallHistoryMessage(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
eraId: string
|
eraId: string
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue