mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
perf(replies): prefer cached board preview replies (#1101)
* perf(replies): prefer cached board preview replies * fix(replies): address review feedback
This commit is contained in:
@@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { copyToClipboard } from '../clipboard-utils';
|
||||
import { hashStringToColor, getTextColorForBackground, removeMarkdown } from '../post-utils';
|
||||
import { preloadReplyModal, preloadThemeAssets, resolveAssetUrl } from '../preload-utils';
|
||||
import { computeOmittedCount, filterRepliesForDisplay, getPreviewDisplayReplies, getTotalReplyCount } from '../replies-preview-utils';
|
||||
import { computeOmittedCount, filterRepliesForDisplay, getPreviewDisplayReplies, getTotalReplyCount, hasEnoughPreviewReplies } from '../replies-preview-utils';
|
||||
import { getQuotedCidsFromContent, mergeQuotedCids } from '../reply-quote-utils';
|
||||
import { formatUserIDForDisplay, truncateWithEllipsisInMiddle } from '../string-utils';
|
||||
import { getFormattedDate, getFormattedTimeAgo, isChristmas } from '../time-utils';
|
||||
@@ -186,6 +186,10 @@ describe('misc utils', () => {
|
||||
|
||||
expect(computeOmittedCount({ totalReplyCount: 2, visibleCount: 5 })).toBe(0);
|
||||
expect(computeOmittedCount({ totalReplyCount: 9, visibleCount: 5 })).toBe(4);
|
||||
expect(hasEnoughPreviewReplies({ replyCount: 2, loadedCount: 2, visibleCount: 5 })).toBe(true);
|
||||
expect(hasEnoughPreviewReplies({ replyCount: 9, loadedCount: 4, visibleCount: 5 })).toBe(false);
|
||||
expect(hasEnoughPreviewReplies({ replyCount: undefined, loadedCount: 5, visibleCount: 5 })).toBe(true);
|
||||
expect(hasEnoughPreviewReplies({ replyCount: undefined, loadedCount: 4, visibleCount: 5 })).toBe(false);
|
||||
expect(getTotalReplyCount({ replyCount: undefined, fullLoadedCount: 7, previewLoadedCount: 5 })).toBe(7);
|
||||
expect(getTotalReplyCount({ replyCount: 12, fullLoadedCount: 7, previewLoadedCount: 5 })).toBe(12);
|
||||
});
|
||||
|
||||
@@ -54,6 +54,22 @@ export function computeOmittedCount({ totalReplyCount, visibleCount }: ComputeOm
|
||||
return Math.max(0, totalReplyCount - visibleCount);
|
||||
}
|
||||
|
||||
interface HasEnoughPreviewRepliesParams {
|
||||
replyCount: number | undefined;
|
||||
loadedCount: number;
|
||||
visibleCount: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Board previews can skip a live fetch when cached replies already cover all
|
||||
* replies that could be shown. If total reply count is unknown, require a full
|
||||
* visible slice so UX matches the current live-preview behavior.
|
||||
*/
|
||||
export function hasEnoughPreviewReplies({ replyCount, loadedCount, visibleCount }: HasEnoughPreviewRepliesParams): boolean {
|
||||
const requiredCount = typeof replyCount === 'number' && replyCount >= 0 ? Math.min(visibleCount, replyCount) : visibleCount;
|
||||
return requiredCount === 0 || loadedCount >= requiredCount;
|
||||
}
|
||||
|
||||
interface GetTotalReplyCountParams {
|
||||
replyCount: number | undefined;
|
||||
fullLoadedCount: number;
|
||||
|
||||
Reference in New Issue
Block a user