mirror of
https://github.com/wassname/talk.git
synced 2026-07-26 13:37:38 +08:00
Another optimization pass
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
const _ = require('lodash');
|
||||
const DataLoader = require('dataloader');
|
||||
const util = require('./util');
|
||||
const objectCacheKeyFn = util.objectCacheKeyFn;
|
||||
const arrayCacheKeyFn = util.arrayCacheKeyFn;
|
||||
const {objectCacheKeyFn} = require('./util');
|
||||
|
||||
const CommentModel = require('../../models/comment');
|
||||
const ActionModel = require('../../models/action');
|
||||
@@ -29,7 +27,7 @@ const getMetrics = ({loaders: {Metrics, Assets}}, {from, to, sort, limit}) => {
|
||||
let commentIDs = _.uniq(actionSummaries.map((as) => as.item_id));
|
||||
|
||||
// Find those comments.
|
||||
return Metrics.getSpecificComments.load(commentIDs);
|
||||
return Metrics.getSpecificComments.loadMany(commentIDs);
|
||||
})
|
||||
.then((commentResults) => {
|
||||
|
||||
@@ -160,10 +158,7 @@ const getSpecificComments = (context, ids) => {
|
||||
|
||||
module.exports = (context) => ({
|
||||
Metrics: {
|
||||
getSpecificComments: new DataLoader(([ids]) => getSpecificComments(context, ids).then((c) => [c]), {
|
||||
batch: false,
|
||||
cacheKeyFn: arrayCacheKeyFn
|
||||
}),
|
||||
getSpecificComments: new DataLoader((ids) => getSpecificComments(context, ids)),
|
||||
getRecentActions: new DataLoader(([{from, to}]) => getRecentActions(context, {from, to}).then((as) => [as]), {
|
||||
batch: false,
|
||||
cacheKeyFn: objectCacheKeyFn('from', 'to')
|
||||
|
||||
Reference in New Issue
Block a user