Skip to content

Commit 6651f2b

Browse files
Bug/cache select (#576)
1 parent b66b23a commit 6651f2b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/services/cache.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ module.exports = function (cacheMap, keyFieldName, options = {}) {
1313
let items = getItems(context);
1414
items = Array.isArray(items) ? items : [items];
1515

16+
const query = context.params.query || {};
17+
1618
if (context.type === 'after') {
1719
if (context.method === 'remove') return;
1820

19-
const $select = (context.params.query || {}).$select;
20-
if (context.method === 'find' && $select) return;
21+
if (query.$select) return;
2122

2223
items.forEach(item => {
2324
const idName = getIdName(keyFieldName, item);
@@ -33,10 +34,11 @@ module.exports = function (cacheMap, keyFieldName, options = {}) {
3334
case 'create':
3435
return;
3536
case 'get': {
36-
const key = makeCacheKey(context.id);
37-
const value = cacheMap.get(key);
38-
39-
if (value) context.result = value;
37+
if (!Object.keys(query).length) {
38+
const key = makeCacheKey(context.id);
39+
const value = cacheMap.get(key);
40+
if (value) context.result = value;
41+
}
4042
return context;
4143
} default: // update, patch, remove
4244
if (context.id) {

0 commit comments

Comments
 (0)