diff options
| author | MeiMei <30769358+mei23@users.noreply.github.com> | 2019-04-17 00:45:33 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2019-04-17 00:45:33 +0900 |
| commit | b1865047187bf6fc9d4ad3b56a0d4eb6b2817c2b (patch) | |
| tree | 17a8a34528095c0b34283fd684f7939be66f087f /src/misc | |
| parent | Refactor (diff) | |
| download | sharkey-b1865047187bf6fc9d4ad3b56a0d4eb6b2817c2b.tar.gz sharkey-b1865047187bf6fc9d4ad3b56a0d4eb6b2817c2b.tar.bz2 sharkey-b1865047187bf6fc9d4ad3b56a0d4eb6b2817c2b.zip | |
Metaのアクセスでトランザクションを張るように (#4720)
* admin/instanceでmetaをキャッシュしないように
* Metaのアクセスにトランザクションをかける
Diffstat (limited to 'src/misc')
| -rw-r--r-- | src/misc/fetch-meta.ts | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/misc/fetch-meta.ts b/src/misc/fetch-meta.ts index a459f07729..800f0b9e63 100644 --- a/src/misc/fetch-meta.ts +++ b/src/misc/fetch-meta.ts @@ -1,13 +1,21 @@ import { Meta } from '../models/entities/meta'; -import { Metas } from '../models'; +import { getConnection } from 'typeorm'; export default async function(): Promise<Meta> { - const meta = await Metas.findOne(); - if (meta) { - return meta; - } else { - return Metas.save({ - id: 'x' - } as Meta); - } + return await getConnection().transaction(async transactionalEntityManager => { + // バグでレコードが複数出来てしまっている可能性があるので新しいIDを優先する + const meta = await transactionalEntityManager.findOne(Meta, { + order: { + id: 'DESC' + } + }); + + if (meta) { + return meta; + } else { + return await transactionalEntityManager.save(Meta, { + id: 'x' + }) as Meta; + } + }); } |