mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 16:02:26 +00:00
Merge pull request #1044 from PR0M3TH3AN/codex/update-getcommentcachekey-for-videoeventid
Normalize comment cache keys for mixed-case IDs
This commit is contained in:
2 files changed
+40
-1
No files matched your search
@@ -324,7 +324,11 @@ export default class CommentThreadService {
|
||||
|
||||
getCommentCacheKey(videoEventId) {
|
||||
const normalized = normalizeString(videoEventId);
|
||||
return normalized ? `${COMMENT_CACHE_PREFIX}${normalized}` : "";
|
||||
if (!normalized) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return `${COMMENT_CACHE_PREFIX}${normalized.toLowerCase()}`;
|
||||
}
|
||||
|
||||
getCachedComments(videoEventId) {
|
||||
|
||||
@@ -88,6 +88,41 @@ test.after(() => {
|
||||
}
|
||||
});
|
||||
|
||||
test("CommentThreadService caches mixed-case video ids consistently", () => {
|
||||
const videoEventId = "VideoMixed123";
|
||||
const service = new CommentThreadService();
|
||||
|
||||
const comments = [
|
||||
{
|
||||
id: "comment-1",
|
||||
pubkey: "authorpk",
|
||||
content: "Cached comment",
|
||||
created_at: 1700000000,
|
||||
tags: [],
|
||||
},
|
||||
];
|
||||
|
||||
service.cacheComments(videoEventId, comments);
|
||||
|
||||
const cachedKeys = [];
|
||||
for (let index = 0; index < localStorage.length; index += 1) {
|
||||
cachedKeys.push(localStorage.key(index));
|
||||
}
|
||||
|
||||
assert.deepEqual(
|
||||
cachedKeys,
|
||||
["bitvid:comments:videomixed123"],
|
||||
"cache key should normalize mixed-case ids",
|
||||
);
|
||||
|
||||
const cached = service.getCachedComments(videoEventId.toLowerCase());
|
||||
assert.deepEqual(
|
||||
cached,
|
||||
comments,
|
||||
"mixed-case ids should retrieve cached entries",
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
"listVideoComments accepts builder events without parent ids and filters replies",
|
||||
async () => {
|
||||
|
||||
Reference in new issue
Block a user