perf: cache media and coalesce realtime sync

This commit is contained in:
winchen
2026-08-03 10:14:02 +08:00
parent b492a5ff76
commit e42bd6a225
9 changed files with 187 additions and 47 deletions
+34 -8
View File
@@ -6281,7 +6281,8 @@ class HttpImClient {
target: conversation.target || conversation.raw?.target || conversation.id.replace(/^single-/, ''),
limit,
conversationType: conversation.type || conversation.raw?.type || 0,
markRead: Boolean(options.markRead)
markRead: Boolean(options.markRead),
includeConversations: Boolean(options.includeConversations)
}, {
withCredentials: false
});
@@ -6293,6 +6294,19 @@ class HttpImClient {
displayTimestamp: message.displayTimestamp || message.timestamp,
conversationId: conversation.id
}));
if (options.includeConversations && Array.isArray(response.data?.result?.conversations)) {
const remoteConversations = response.data.result.conversations.map(remoteConversation => ({
...remoteConversation,
updatedAt: Number(remoteConversation.updatedAt || Date.now()),
avatarText: remoteConversation.avatarText || String(remoteConversation.title || remoteConversation.target || '?').slice(0, 1).toUpperCase(),
raw: remoteConversation.raw || {
type: 'single',
target: remoteConversation.target,
line: 0
}
}));
this.emit('conversationsChanged', remoteConversations);
}
const userId = this.currentUser?.userId || '';
const messagesByConversation = readLocalMessages(userId);
messagesByConversation[conversation.id] = mergeSyncedMessages(messagesByConversation[conversation.id] || [], messages, conversation.id, userId);
@@ -8015,6 +8029,7 @@ const useConversationStore = (0,pinia__WEBPACK_IMPORTED_MODULE_19__/* .defineSto
readPresenceEventsBound: false,
syncInFlight: false,
pendingReadReceiptConversationId: '',
pendingConversationSync: false,
conversationSyncInFlight: false,
messageSyncTimer: null,
messageSyncQueuedAt: 0,
@@ -8126,6 +8141,7 @@ const useConversationStore = (0,pinia__WEBPACK_IMPORTED_MODULE_19__/* .defineSto
this.syncInFlight = false;
this.conversationSyncInFlight = false;
this.pendingReadReceiptConversationId = '';
this.pendingConversationSync = false;
this.lastReadSyncByConversation = {};
this.activeId = '';
this.conversations = [];
@@ -8560,6 +8576,9 @@ const useConversationStore = (0,pinia__WEBPACK_IMPORTED_MODULE_19__/* .defineSto
if (wantsReadReceipt) {
this.pendingReadReceiptConversationId = conversation.id;
}
if (options.includeConversations) {
this.pendingConversationSync = true;
}
return;
}
this.syncInFlight = true;
@@ -8567,7 +8586,8 @@ const useConversationStore = (0,pinia__WEBPACK_IMPORTED_MODULE_19__/* .defineSto
const previousMessages = this.messagesByConversation[syncedConversationId] || [];
try {
const messages = await _services_imClient__WEBPACK_IMPORTED_MODULE_20__/* .imClient */ .wD.fetchRemoteMessages(conversation, 50, {
markRead
markRead,
includeConversations: Boolean(options.includeConversations)
});
if (markRead) {
this.lastReadSyncByConversation = {
@@ -8608,10 +8628,13 @@ const useConversationStore = (0,pinia__WEBPACK_IMPORTED_MODULE_19__/* .defineSto
// Keep the local view usable if a polling request misses.
} finally {
this.syncInFlight = false;
if (this.pendingReadReceiptConversationId === this.activeId && canMarkReadNow()) {
if ((this.pendingReadReceiptConversationId === this.activeId || this.pendingConversationSync) && canMarkReadNow()) {
const includeConversations = this.pendingConversationSync;
this.pendingReadReceiptConversationId = '';
this.pendingConversationSync = false;
this.scheduleActiveMessagesSync({
allowReadReceipt: true
allowReadReceipt: true,
includeConversations
}, 700);
}
}
@@ -8627,7 +8650,8 @@ const useConversationStore = (0,pinia__WEBPACK_IMPORTED_MODULE_19__/* .defineSto
this.pendingMessageSyncOptions = {
...this.pendingMessageSyncOptions,
allowReadReceipt: Boolean(this.pendingMessageSyncOptions.allowReadReceipt || options.allowReadReceipt),
userAction: Boolean(this.pendingMessageSyncOptions.userAction || options.userAction)
userAction: Boolean(this.pendingMessageSyncOptions.userAction || options.userAction),
includeConversations: Boolean(this.pendingMessageSyncOptions.includeConversations || options.includeConversations)
};
const maxWait = 1200;
const runAt = Math.min(now + Math.max(0, Number(delay) || 0), this.messageSyncQueuedAt + maxWait);
@@ -8664,11 +8688,13 @@ const useConversationStore = (0,pinia__WEBPACK_IMPORTED_MODULE_19__/* .defineSto
}
window.clearTimeout(this.realtimeSyncTimer);
this.realtimeSyncTimer = window.setTimeout(() => {
this.refreshRemoteConversations();
if (this.activeId) {
this.scheduleActiveMessagesSync({
allowReadReceipt: canMarkReadNow()
allowReadReceipt: canMarkReadNow(),
includeConversations: true
}, 700);
} else {
this.refreshRemoteConversations();
}
}, 500);
},
@@ -9874,4 +9900,4 @@ const __exports__ = _NavigationRail_vue_vue_type_script_setup_true_lang_js__WEBP
/******/
/******/ })()
;
//# sourceMappingURL=app.a89973f7.js.map
//# sourceMappingURL=app.631b8b2d.js.map
+1
View File
File diff suppressed because one or more lines are too long
-1
View File
File diff suppressed because one or more lines are too long