mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-22 17:03:49 +01:00
Metaのアクセスでトランザクションを張るように (#4720)
* admin/instanceでmetaをキャッシュしないように * Metaのアクセスにトランザクションをかける
This commit is contained in:
parent
0f9e0b9c83
commit
135c99591e
@ -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 New Issue
Block a user