From 6d22032b61dc9ae92200d83fab1e96232c0bdc09 Mon Sep 17 00:00:00 2001 From: mei23 Date: Sun, 4 Oct 2020 11:57:57 +0900 Subject: [PATCH] =?UTF-8?q?INSERT=E3=81=AB=E3=81=AFinsert=E3=82=92?= =?UTF-8?q?=E4=BD=BF=E3=81=86=E3=82=B5=E3=83=B3=E3=83=97=E3=83=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/misc/fetch-meta.ts | 4 ++-- src/remote/activitypub/models/person.ts | 12 ++++++------ src/server/api/common/signup.ts | 16 ++++++++-------- src/server/api/endpoints/admin/update-meta.ts | 2 +- src/server/api/endpoints/channels/create.ts | 4 ++-- src/services/chart/core.ts | 4 ++-- src/services/note/reaction/create.ts | 4 ++-- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/misc/fetch-meta.ts b/src/misc/fetch-meta.ts index 680cf37a7..a087e7698 100644 --- a/src/misc/fetch-meta.ts +++ b/src/misc/fetch-meta.ts @@ -18,9 +18,9 @@ export async function fetchMeta(noCache = false): Promise { cache = meta; return meta; } else { - const saved = await transactionalEntityManager.save(Meta, { + const saved = await transactionalEntityManager.insert(Meta, { id: 'x' - }) as Meta; + }).then(x => transactionalEntityManager.findOneOrFail(Meta, x.identifiers[0])); cache = saved; return saved; diff --git a/src/remote/activitypub/models/person.ts b/src/remote/activitypub/models/person.ts index 9f6392174..7011c04e8 100644 --- a/src/remote/activitypub/models/person.ts +++ b/src/remote/activitypub/models/person.ts @@ -145,7 +145,7 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise { - user = await transactionalEntityManager.save(new User({ + user = await transactionalEntityManager.insert(User, { id: genId(), avatarId: null, bannerId: null, @@ -163,9 +163,9 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise transactionalEntityManager.findOneOrFail(User, x.identifiers[0])) as IRemoteUser; - await transactionalEntityManager.save(new UserProfile({ + await transactionalEntityManager.insert(UserProfile, { userId: user.id, description: person.summary ? htmlToMfm(person.summary, person.tag) : null, url: getOneApHrefNullable(person.url), @@ -173,13 +173,13 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise transactionalEntityManager.findOneOrFail(User, x.identifiers[0])); - await transactionalEntityManager.save(new UserKeypair({ + await transactionalEntityManager.insert(UserKeypair, { publicKey: keyPair[0], privateKey: keyPair[1], userId: account.id - })); + }); - await transactionalEntityManager.save(new UserProfile({ + await transactionalEntityManager.insert(UserProfile, { userId: account.id, autoAcceptFollowed: true, password: hash, - })); + }); - await transactionalEntityManager.save(new UsedUsername({ + await transactionalEntityManager.insert(UsedUsername, { createdAt: new Date(), username: username.toLowerCase(), - })); + }); }); usersChart.update(account, true); diff --git a/src/server/api/endpoints/admin/update-meta.ts b/src/server/api/endpoints/admin/update-meta.ts index fea6cb539..38b5dc09e 100644 --- a/src/server/api/endpoints/admin/update-meta.ts +++ b/src/server/api/endpoints/admin/update-meta.ts @@ -691,7 +691,7 @@ export default define(meta, async (ps, me) => { if (meta) { await transactionalEntityManager.update(Meta, meta.id, set); } else { - await transactionalEntityManager.save(Meta, set); + await transactionalEntityManager.insert(Meta, set); } }); diff --git a/src/server/api/endpoints/channels/create.ts b/src/server/api/endpoints/channels/create.ts index 53436e703..ff41399b3 100644 --- a/src/server/api/endpoints/channels/create.ts +++ b/src/server/api/endpoints/channels/create.ts @@ -55,14 +55,14 @@ export default define(meta, async (ps, user) => { } } - const channel = await Channels.save({ + const channel = await Channels.insert({ id: genId(), createdAt: new Date(), userId: user.id, name: ps.name, description: ps.description || null, bannerId: banner ? banner.id : null, - } as Channel); + }).then(x => Channels.findOneOrFail(x.identifiers[0])); return await Channels.pack(channel, user); }); diff --git a/src/services/chart/core.ts b/src/services/chart/core.ts index dc09923ae..1ff66f73b 100644 --- a/src/services/chart/core.ts +++ b/src/services/chart/core.ts @@ -305,12 +305,12 @@ export default abstract class Chart> { if (currentLog != null) return currentLog; // 新規ログ挿入 - log = await this.repository.save({ + log = await this.repository.insert({ group: group, span: span, date: date, ...Chart.convertObjectToFlattenColumns(data) - }); + }).then(x => this.repository.findOneOrFail(x.identifiers[0])); logger.info(`${this.name + (group ? `:${group}` : '')} (${span}): New commit created`); diff --git a/src/services/note/reaction/create.ts b/src/services/note/reaction/create.ts index bfa95b087..2f21daa57 100644 --- a/src/services/note/reaction/create.ts +++ b/src/services/note/reaction/create.ts @@ -33,13 +33,13 @@ export default async (user: User, note: Note, reaction?: string) => { } // Create reaction - const inserted = await NoteReactions.save({ + const inserted = await NoteReactions.insert({ id: genId(), createdAt: new Date(), noteId: note.id, userId: user.id, reaction - }); + }).then(x => NoteReactions.findOneOrFail(x.identifiers[0])); // Increment reactions count const sql = `jsonb_set("reactions", '{${reaction}}', (COALESCE("reactions"->>'${reaction}', '0')::int + 1)::text::jsonb)`;