From f2f7bdc5a9d3f55479e32721367017980b04a51e Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Fri, 23 Nov 2018 23:12:28 +0900 Subject: [PATCH] Do not use _replyIds (#3392) --- src/models/note.ts | 4 +++- src/server/api/endpoints/notes/replies.ts | 17 +++++++---------- src/services/note/create.ts | 3 --- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/models/note.ts b/src/models/note.ts index 717960bb2..e76fc88a4 100644 --- a/src/models/note.ts +++ b/src/models/note.ts @@ -18,6 +18,7 @@ Note.createIndex('uri', { sparse: true, unique: true }); Note.createIndex('userId'); Note.createIndex('mentions'); Note.createIndex('visibleUserIds'); +Note.createIndex('replyId'); Note.createIndex('tagsLower'); Note.createIndex('_user.host'); Note.createIndex('_files._id'); @@ -99,7 +100,6 @@ export type INote = { host: string; inbox?: string; }; - _replyIds?: mongo.ObjectID[]; _files?: IDriveFile[]; }; @@ -258,6 +258,8 @@ export const pack = async ( delete _note._reply; delete _note._renote; delete _note._files; + delete _note._replyIds; + if (_note.geo) delete _note.geo.type; // Populate user diff --git a/src/server/api/endpoints/notes/replies.ts b/src/server/api/endpoints/notes/replies.ts index 6046b9b31..6c2b690ab 100644 --- a/src/server/api/endpoints/notes/replies.ts +++ b/src/server/api/endpoints/notes/replies.ts @@ -33,16 +33,13 @@ export const meta = { }; export default define(meta, (ps, user) => new Promise(async (res, rej) => { - // Lookup note - const note = await Note.findOne({ - _id: ps.noteId - }); - if (note === null) { - return rej('note not found'); - } + const notes = await Note.find({ + replyId: ps.noteId + }, { + limit: ps.limit, + skip: ps.offset + }); - const ids = (note._replyIds || []).slice(ps.offset, ps.offset + ps.limit); - - res(await packMany(ids, user)); + res(await packMany(notes, user)); })); diff --git a/src/services/note/create.ts b/src/services/note/create.ts index eac0185e7..5e4dfd22e 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -622,9 +622,6 @@ function saveQuote(renote: INote, note: INote) { function saveReply(reply: INote, note: INote) { Note.update({ _id: reply._id }, { - $push: { - _replyIds: note._id - }, $inc: { repliesCount: 1 }