This commit is contained in:
tamaina 2023-08-11 15:20:34 +00:00
parent 588679f4bc
commit 1f50db3286
1 changed files with 42 additions and 48 deletions

View File

@ -107,14 +107,6 @@ export class NoteManager {
} }
public set(_note: Note): void { public set(_note: Note): void {
if (this.updatedAt.has(_note.id)) {
if (this.updatedAt.get(_note.id)! + 100 > Date.now()) {
if (this.isDebuggerEnabled) console.log('NoteManager: set ignore', _note.id);
// 100ms以内に更新されたートは無視computedが壊れるので
return;
}
}
const note: Note = { ..._note }; const note: Note = { ..._note };
userLiteManager.set(note.user); userLiteManager.set(note.user);
@ -157,9 +149,7 @@ export class NoteManager {
this.updatedAt.set(note.id, Date.now()); this.updatedAt.set(note.id, Date.now());
} }
public get(id: string): CachedNote { public getRaw(id: string): Note | null {
if (!this.notesComputed.has(id)) {
this.notesComputed.set(id, computed<Note | null>(() => {
const note = this.notesSource.value.get(id); const note = this.notesSource.value.get(id);
if (this.isDebuggerEnabled) console.log('NoteManager: compute note', id, note); if (this.isDebuggerEnabled) console.log('NoteManager: compute note', id, note);
@ -171,16 +161,16 @@ export class NoteManager {
const user = userLiteManager.get(note.userId)!; const user = userLiteManager.get(note.userId)!;
const renote = note.renoteId ? this.get(note.renoteId) : undefined; const renote = note.renoteId ? this.getRaw(note.renoteId) : undefined;
// renoteが削除されている場合はCASCADE削除されるためnullを返す // renoteが削除されている場合はCASCADE削除されるためnullを返す
if (renote && !renote.value) { if (!renote) {
if (this.isDebuggerEnabled) console.log('NoteManager: compute note: renote is null', id, note.renoteId); if (this.isDebuggerEnabled) console.log('NoteManager: compute note: renote is null', id, note.renoteId);
return null; return null;
} }
const reply = note.replyId ? this.get(note.replyId) : undefined; const reply = note.replyId ? this.getRaw(note.replyId) : undefined;
// replyが削除されている場合はCASCADE削除されるためnullを返す // replyが削除されている場合はCASCADE削除されるためnullを返す
if (reply && !reply.value) { if (!reply) {
if (this.isDebuggerEnabled) console.log('NoteManager: compute note: reply is null', id, note.replyId); if (this.isDebuggerEnabled) console.log('NoteManager: compute note: reply is null', id, note.replyId);
return null; return null;
} }
@ -190,15 +180,19 @@ export class NoteManager {
const result = { const result = {
...note, ...note,
user: user.value, user: user.value,
renote: renote?.value ?? undefined, renote: renote ?? undefined,
reply: reply?.value ?? undefined, reply: reply ?? undefined,
files: files.filter(file => file) as DriveFile[], files: files.filter(file => file) as DriveFile[],
}; };
if (this.isDebuggerEnabled) console.log('NoteManager: compute note: not null', id, result); if (this.isDebuggerEnabled) console.log('NoteManager: compute note: not null', id, result);
return result; return result;
})); }
public get(id: string): CachedNote {
if (!this.notesComputed.has(id)) {
this.notesComputed.set(id, computed<Note | null>(() => this.getRaw(id)));
if (this.isDebuggerEnabled) console.log('NoteManager: get note (new)', id, this.notesComputed.get(id)); if (this.isDebuggerEnabled) console.log('NoteManager: get note (new)', id, this.notesComputed.get(id));
} else { } else {
if (this.isDebuggerEnabled) console.log('NoteManager: get note (cached)', id, this.notesComputed.get(id), this.notesSource.value.get(id)); if (this.isDebuggerEnabled) console.log('NoteManager: get note (cached)', id, this.notesComputed.get(id), this.notesSource.value.get(id));