mirror of
https://github.com/kokonect-link/cherrypick
synced 2024-12-12 05:38:55 +09:00
Enable query result cache for meta / stats / hashtags trend (#4978)
This commit is contained in:
parent
3ea7a49c1c
commit
7e7f94d685
@ -96,6 +96,18 @@ export function initDb(justBorrow = false, sync = false, log = false) {
|
|||||||
extra: config.db.extra,
|
extra: config.db.extra,
|
||||||
synchronize: process.env.NODE_ENV === 'test' || sync,
|
synchronize: process.env.NODE_ENV === 'test' || sync,
|
||||||
dropSchema: process.env.NODE_ENV === 'test' && !justBorrow,
|
dropSchema: process.env.NODE_ENV === 'test' && !justBorrow,
|
||||||
|
cache: {
|
||||||
|
type: 'redis',
|
||||||
|
options: {
|
||||||
|
host: config.redis.host,
|
||||||
|
port: config.redis.port,
|
||||||
|
options:{
|
||||||
|
auth_pass: config.redis.pass,
|
||||||
|
prefix: config.redis.prefix,
|
||||||
|
db: config.redis.db || 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
logging: log,
|
logging: log,
|
||||||
logger: log ? new MyCustomLogger() : undefined,
|
logger: log ? new MyCustomLogger() : undefined,
|
||||||
entities: [
|
entities: [
|
||||||
|
@ -59,6 +59,7 @@ export default define(meta, async () => {
|
|||||||
.where(`note.createdAt > :date`, { date: new Date(Date.now() - rangeA) })
|
.where(`note.createdAt > :date`, { date: new Date(Date.now() - rangeA) })
|
||||||
.andWhere(`note.tags != '{}'`)
|
.andWhere(`note.tags != '{}'`)
|
||||||
.select(['note.tags', 'note.userId'])
|
.select(['note.tags', 'note.userId'])
|
||||||
|
.cache(60000) // 1 min
|
||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
if (tagNotes.length === 0) {
|
if (tagNotes.length === 0) {
|
||||||
@ -108,6 +109,7 @@ export default define(meta, async () => {
|
|||||||
.where(':tag = ANY(note.tags)', { tag: tag })
|
.where(':tag = ANY(note.tags)', { tag: tag })
|
||||||
.andWhere('note.createdAt < :lt', { lt: new Date(Date.now() - (interval * i)) })
|
.andWhere('note.createdAt < :lt', { lt: new Date(Date.now() - (interval * i)) })
|
||||||
.andWhere('note.createdAt > :gt', { gt: new Date(Date.now() - (interval * (i + 1))) })
|
.andWhere('note.createdAt > :gt', { gt: new Date(Date.now() - (interval * (i + 1))) })
|
||||||
|
.cache(60000) // 1 min
|
||||||
.getRawOne()
|
.getRawOne()
|
||||||
.then(x => parseInt(x.count, 10))
|
.then(x => parseInt(x.count, 10))
|
||||||
)));
|
)));
|
||||||
@ -119,6 +121,7 @@ export default define(meta, async () => {
|
|||||||
.select('count(distinct note.userId)')
|
.select('count(distinct note.userId)')
|
||||||
.where(':tag = ANY(note.tags)', { tag: tag })
|
.where(':tag = ANY(note.tags)', { tag: tag })
|
||||||
.andWhere('note.createdAt > :gt', { gt: new Date(Date.now() - (interval * range)) })
|
.andWhere('note.createdAt > :gt', { gt: new Date(Date.now() - (interval * range)) })
|
||||||
|
.cache(60000) // 1 min
|
||||||
.getRawOne()
|
.getRawOne()
|
||||||
.then(x => parseInt(x.count, 10))
|
.then(x => parseInt(x.count, 10))
|
||||||
));
|
));
|
||||||
|
@ -94,7 +94,7 @@ export const meta = {
|
|||||||
export default define(meta, async (ps, me) => {
|
export default define(meta, async (ps, me) => {
|
||||||
const instance = await fetchMeta(true);
|
const instance = await fetchMeta(true);
|
||||||
|
|
||||||
const emojis = await Emojis.find({ host: null });
|
const emojis = await Emojis.find({ where: { host: null }, cache: 3600000 }); // 1 hour
|
||||||
|
|
||||||
const response: any = {
|
const response: any = {
|
||||||
maintainerName: instance.maintainerName,
|
maintainerName: instance.maintainerName,
|
||||||
|
@ -57,10 +57,10 @@ export default define(meta, async () => {
|
|||||||
driveUsageLocal,
|
driveUsageLocal,
|
||||||
driveUsageRemote
|
driveUsageRemote
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
Notes.count(),
|
Notes.count({ cache: 3600000 }), // 1 hour
|
||||||
Notes.count({ userHost: null }),
|
Notes.count({ where: { userHost: null }, cache: 3600000 }),
|
||||||
Users.count(),
|
Users.count({ cache: 3600000 }),
|
||||||
Users.count({ host: null }),
|
Users.count({ where: { host: null }, cache: 3600000 }),
|
||||||
federationChart.getChart('hour', 1).then(chart => chart.instance.total[0]),
|
federationChart.getChart('hour', 1).then(chart => chart.instance.total[0]),
|
||||||
driveChart.getChart('hour', 1).then(chart => chart.local.totalSize[0]),
|
driveChart.getChart('hour', 1).then(chart => chart.local.totalSize[0]),
|
||||||
driveChart.getChart('hour', 1).then(chart => chart.remote.totalSize[0]),
|
driveChart.getChart('hour', 1).then(chart => chart.remote.totalSize[0]),
|
||||||
|
Loading…
Reference in New Issue
Block a user