perf: cache media and coalesce realtime sync
This commit is contained in:
+51
-15
@@ -1521,11 +1521,27 @@ function loadRecentConversations(PDO $db, string $userId, int $limit): array
|
||||
return array_slice($conversations, 0, $limit);
|
||||
}
|
||||
|
||||
function messageSyncResult(
|
||||
PDO $db,
|
||||
string $userId,
|
||||
array $messages,
|
||||
bool $includeConversations,
|
||||
int $limit
|
||||
): array {
|
||||
$result = ['messages' => $messages];
|
||||
if ($includeConversations) {
|
||||
$result['conversations'] = loadRecentConversations($db, $userId, $limit);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
$payload = readJsonPayload();
|
||||
$userId = trim((string)($payload['userId'] ?? ''));
|
||||
$target = trim((string)($payload['target'] ?? ''));
|
||||
$limit = clampLimit($payload['limit'] ?? 50, 50, 100);
|
||||
$markRead = payloadBool($payload['markRead'] ?? false);
|
||||
$includeConversations = payloadBool($payload['includeConversations'] ?? false);
|
||||
$conversationType = normalizeConversationType($payload['conversationType'] ?? $payload['type'] ?? 0);
|
||||
|
||||
if ($userId === '') {
|
||||
@@ -1540,28 +1556,48 @@ try {
|
||||
if ($target !== '') {
|
||||
if ($conversationType === 'group') {
|
||||
if (isWebGroupTarget(imAppDb(), $target)) {
|
||||
respond(0, 'success', [
|
||||
'messages' => loadWebGroupMessages(imAppDb(), $userId, $target, $limit, $markRead),
|
||||
]);
|
||||
respond(0, 'success', messageSyncResult(
|
||||
$db,
|
||||
$userId,
|
||||
loadWebGroupMessages(imAppDb(), $userId, $target, $limit, $markRead),
|
||||
$includeConversations,
|
||||
$limit
|
||||
));
|
||||
}
|
||||
if (isNativeGroupTarget($db, $target)) {
|
||||
respond(0, 'success', [
|
||||
'messages' => loadNativeGroupMessages($db, $userId, $target, $limit, $markRead),
|
||||
]);
|
||||
respond(0, 'success', messageSyncResult(
|
||||
$db,
|
||||
$userId,
|
||||
loadNativeGroupMessages($db, $userId, $target, $limit, $markRead),
|
||||
$includeConversations,
|
||||
$limit
|
||||
));
|
||||
}
|
||||
respond(0, 'success', [
|
||||
'messages' => [],
|
||||
]);
|
||||
respond(0, 'success', messageSyncResult(
|
||||
$db,
|
||||
$userId,
|
||||
[],
|
||||
$includeConversations,
|
||||
$limit
|
||||
));
|
||||
}
|
||||
if (isWebGroupTarget(imAppDb(), $target)) {
|
||||
respond(0, 'success', [
|
||||
'messages' => loadWebGroupMessages(imAppDb(), $userId, $target, $limit, $markRead),
|
||||
]);
|
||||
respond(0, 'success', messageSyncResult(
|
||||
$db,
|
||||
$userId,
|
||||
loadWebGroupMessages(imAppDb(), $userId, $target, $limit, $markRead),
|
||||
$includeConversations,
|
||||
$limit
|
||||
));
|
||||
}
|
||||
$targetId = resolveUserId($db, $target);
|
||||
respond(0, 'success', [
|
||||
'messages' => loadConversationMessages($db, $userId, $targetId, $limit, $markRead),
|
||||
]);
|
||||
respond(0, 'success', messageSyncResult(
|
||||
$db,
|
||||
$userId,
|
||||
loadConversationMessages($db, $userId, $targetId, $limit, $markRead),
|
||||
$includeConversations,
|
||||
$limit
|
||||
));
|
||||
}
|
||||
|
||||
respond(0, 'success', [
|
||||
|
||||
Reference in New Issue
Block a user