Cache meta
This commit is contained in:
parent
8a55bdd89d
commit
5aa5896b22
34 changed files with 62 additions and 55 deletions
|
@ -1,7 +1,11 @@
|
|||
import { Meta } from '../models/entities/meta';
|
||||
import { getConnection } from 'typeorm';
|
||||
|
||||
export default async function(): Promise<Meta> {
|
||||
let cache: Meta;
|
||||
|
||||
export async function fetchMeta(noCache = false): Promise<Meta> {
|
||||
if (!noCache && cache) return cache;
|
||||
|
||||
return await getConnection().transaction(async transactionalEntityManager => {
|
||||
// バグでレコードが複数出来てしまっている可能性があるので新しいIDを優先する
|
||||
const meta = await transactionalEntityManager.findOne(Meta, {
|
||||
|
@ -11,11 +15,21 @@ export default async function(): Promise<Meta> {
|
|||
});
|
||||
|
||||
if (meta) {
|
||||
cache = meta;
|
||||
return meta;
|
||||
} else {
|
||||
return await transactionalEntityManager.save(Meta, {
|
||||
const saved = await transactionalEntityManager.save(Meta, {
|
||||
id: 'x'
|
||||
}) as Meta;
|
||||
|
||||
cache = saved;
|
||||
return saved;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setInterval(() => {
|
||||
fetchMeta(true).then(meta => {
|
||||
cache = meta;
|
||||
});
|
||||
}, 5000);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import fetchMeta from './fetch-meta';
|
||||
import { fetchMeta } from './fetch-meta';
|
||||
import { ILocalUser } from '../models/entities/user';
|
||||
import { Users } from '../models';
|
||||
import { ensure } from '../prelude/ensure';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { emojiRegex } from './emoji-regex';
|
||||
import fetchMeta from './fetch-meta';
|
||||
import { fetchMeta } from './fetch-meta';
|
||||
import { Emojis } from '../models';
|
||||
|
||||
const basic10: Record<string, string> = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue