Skip to content
This repository was archived by the owner on Aug 27, 2025. It is now read-only.

Commit 232176a

Browse files
committed
feat: cache note
1 parent 533fe6b commit 232176a

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

src/content-script/hooks/twitter.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ let crossSyncToggleEl: HTMLDivElement;
1414

1515
class TwitterHook {
1616
hooks: Hook[];
17-
main: Main;
17+
private main: Main;
18+
private noteCache: Map<string, NoteInput>;
1819

1920
constructor(main: Main) {
2021
this.main = main;
22+
this.noteCache = new Map();
2123

2224
this.hooks = [
2325
{
@@ -276,15 +278,22 @@ class TwitterHook {
276278
].filter((url) => !!url) as string[];
277279
const syncStatus = createApp(SyncStatus, {
278280
getNote: async () => {
279-
// Check if it's already synced
280-
const unidata = await this.main.getUnidata();
281-
const noteResp = await unidata?.notes.get({
282-
source: 'Crossbell Note',
283-
filter: {
284-
url: link,
285-
},
286-
});
287-
return noteResp?.list[0];
281+
if (this.noteCache.has(link)) {
282+
return this.noteCache.get(link);
283+
} else {
284+
// Check if it's already synced
285+
const unidata = await this.main.getUnidata();
286+
const noteResp = await unidata?.notes.get({
287+
source: 'Crossbell Note',
288+
filter: {
289+
url: link,
290+
},
291+
});
292+
if (noteResp?.list[0]) {
293+
this.noteCache.set(link, noteResp?.list[0]);
294+
}
295+
return noteResp?.list[0];
296+
}
288297
},
289298
postNote: async () => {
290299
let newNoteID = '';

0 commit comments

Comments
 (0)