mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-11-23 06:25:14 +00:00
Metaのアクセスでトランザクションを張るように (#4720)
* admin/instanceでmetaをキャッシュしないように * Metaのアクセスにトランザクションをかける
This commit is contained in:
parent
fc27890f13
commit
b186504718
3 changed files with 31 additions and 17 deletions
|
@ -195,7 +195,7 @@ export default Vue.extend({
|
|||
},
|
||||
|
||||
created() {
|
||||
this.$root.getMeta().then(meta => {
|
||||
this.$root.getMeta(true).then(meta => {
|
||||
this.maintainerName = meta.maintainerName;
|
||||
this.maintainerEmail = meta.maintainerEmail;
|
||||
this.disableRegistration = meta.disableRegistration;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import $ from 'cafy';
|
||||
import define from '../../define';
|
||||
import { Metas } from '../../../../models';
|
||||
import { getConnection } from 'typeorm';
|
||||
import { Meta } from '../../../../models/entities/meta';
|
||||
|
||||
export const meta = {
|
||||
|
@ -505,11 +505,17 @@ export default define(meta, async (ps) => {
|
|||
set.swPrivateKey = ps.swPrivateKey;
|
||||
}
|
||||
|
||||
const meta = await Metas.findOne();
|
||||
await getConnection().transaction(async transactionalEntityManager => {
|
||||
const meta = await transactionalEntityManager.findOne(Meta, {
|
||||
order: {
|
||||
id: 'DESC'
|
||||
}
|
||||
});
|
||||
|
||||
if (meta) {
|
||||
await Metas.update(meta.id, set);
|
||||
} else {
|
||||
await Metas.save(set);
|
||||
}
|
||||
if (meta) {
|
||||
await transactionalEntityManager.update(Meta, meta.id, set);
|
||||
} else {
|
||||
await transactionalEntityManager.save(Meta, set);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue