Incorporate limit
This commit is contained in:
@ -1,9 +1,10 @@
|
|||||||
|
// @flow
|
||||||
import debug from 'debug';
|
import debug from 'debug';
|
||||||
|
|
||||||
const debugCache = debug('cache');
|
const debugCache = debug('cache');
|
||||||
|
|
||||||
export default function cache() {
|
export default function cache() {
|
||||||
return async function cacheMiddleware(ctx, next) {
|
return async function cacheMiddleware(ctx: Object, next: Function) {
|
||||||
ctx.cache = {};
|
ctx.cache = {};
|
||||||
|
|
||||||
ctx.cache.set = async (id, value) => {
|
ctx.cache.set = async (id, value) => {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// @flow
|
// @flow
|
||||||
|
import _ from 'lodash';
|
||||||
import { User, Document, View } from '../models';
|
import { User, Document, View } from '../models';
|
||||||
import presentUser from './user';
|
import presentUser from './user';
|
||||||
import presentCollection from './collection';
|
import presentCollection from './collection';
|
||||||
@ -43,9 +44,7 @@ async function present(ctx: Object, document: Document, options: Object = {}) {
|
|||||||
// This could be further optimized by using ctx.cache
|
// This could be further optimized by using ctx.cache
|
||||||
data.collaborators = await User.findAll({
|
data.collaborators = await User.findAll({
|
||||||
where: {
|
where: {
|
||||||
id: {
|
id: { $in: _.takeRight(document.collaboratorIds, 10) || [] },
|
||||||
$in: document.collaboratorIds || [],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}).map(user => presentUser(ctx, user));
|
}).map(user => presentUser(ctx, user));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user