Metaのアクセスでトランザクションを張るように (#4720)
* admin/instanceでmetaをキャッシュしないように * Metaのアクセスにトランザクションをかける
This commit is contained in:
parent
fc27890f13
commit
b186504718
@ -195,7 +195,7 @@ export default Vue.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
this.$root.getMeta().then(meta => {
|
this.$root.getMeta(true).then(meta => {
|
||||||
this.maintainerName = meta.maintainerName;
|
this.maintainerName = meta.maintainerName;
|
||||||
this.maintainerEmail = meta.maintainerEmail;
|
this.maintainerEmail = meta.maintainerEmail;
|
||||||
this.disableRegistration = meta.disableRegistration;
|
this.disableRegistration = meta.disableRegistration;
|
||||||
|
@ -1,13 +1,21 @@
|
|||||||
import { Meta } from '../models/entities/meta';
|
import { Meta } from '../models/entities/meta';
|
||||||
import { Metas } from '../models';
|
import { getConnection } from 'typeorm';
|
||||||
|
|
||||||
export default async function(): Promise<Meta> {
|
export default async function(): Promise<Meta> {
|
||||||
const meta = await Metas.findOne();
|
return await getConnection().transaction(async transactionalEntityManager => {
|
||||||
if (meta) {
|
// バグでレコードが複数出来てしまっている可能性があるので新しいIDを優先する
|
||||||
return meta;
|
const meta = await transactionalEntityManager.findOne(Meta, {
|
||||||
} else {
|
order: {
|
||||||
return Metas.save({
|
id: 'DESC'
|
||||||
id: 'x'
|
}
|
||||||
} as Meta);
|
});
|
||||||
}
|
|
||||||
|
if (meta) {
|
||||||
|
return meta;
|
||||||
|
} else {
|
||||||
|
return await transactionalEntityManager.save(Meta, {
|
||||||
|
id: 'x'
|
||||||
|
}) as Meta;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import $ from 'cafy';
|
import $ from 'cafy';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import { Metas } from '../../../../models';
|
import { getConnection } from 'typeorm';
|
||||||
import { Meta } from '../../../../models/entities/meta';
|
import { Meta } from '../../../../models/entities/meta';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
@ -505,11 +505,17 @@ export default define(meta, async (ps) => {
|
|||||||
set.swPrivateKey = ps.swPrivateKey;
|
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) {
|
if (meta) {
|
||||||
await Metas.update(meta.id, set);
|
await transactionalEntityManager.update(Meta, meta.id, set);
|
||||||
} else {
|
} else {
|
||||||
await Metas.save(set);
|
await transactionalEntityManager.save(Meta, set);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user