mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Moved Tags Content API to api-level caching
refs https://github.com/TryGhost/Toolbox/issues/522 - Caching on a repository level was pretty hard to achieve with more complex models like "posts", so that approach was abandoned in favor of API-response level caching. - Also removed use of "public-resource-repository" as it was not serving any specific purpose anymore.
This commit is contained in:
parent
33f176a9de
commit
b8bdd3e742
2 changed files with 23 additions and 11 deletions
|
@ -14,6 +14,7 @@ module.exports = {
|
|||
docName: 'tags',
|
||||
|
||||
browse: {
|
||||
cache: tagsPublicService.api?.cache,
|
||||
options: [
|
||||
'include',
|
||||
'filter',
|
||||
|
@ -32,7 +33,7 @@ module.exports = {
|
|||
},
|
||||
permissions: true,
|
||||
query(frame) {
|
||||
return tagsPublicService.api.browse(frame.options);
|
||||
return models.TagPublic.findPage(frame.options);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -6,24 +6,35 @@ class TagsPublicServiceWrapper {
|
|||
}
|
||||
|
||||
// Wire up all the dependencies
|
||||
const {TagPublic} = require('../../models');
|
||||
const adapterManager = require('../adapter-manager');
|
||||
const config = require('../../../shared/config');
|
||||
const EventAwareCacheWrapper = require('@tryghost/event-aware-cache-wrapper');
|
||||
const EventRegistry = require('../../lib/common/events');
|
||||
|
||||
let tagsCache;
|
||||
if (config.get('hostSettings:tagsPublicCache:enabled')) {
|
||||
tagsCache = adapterManager.getAdapter('cache:tagsPublic');
|
||||
let tagsPublicCache = adapterManager.getAdapter('cache:tagsPublic');
|
||||
tagsCache = new EventAwareCacheWrapper({
|
||||
cache: tagsPublicCache,
|
||||
resetEvents: ['site.changed'],
|
||||
eventRegistry: EventRegistry
|
||||
});
|
||||
}
|
||||
|
||||
const {PublicResourcesRepository} = require('@tryghost/public-resource-repository');
|
||||
|
||||
this.tagsPublicRepository = new PublicResourcesRepository({
|
||||
Model: TagPublic,
|
||||
cache: tagsCache
|
||||
});
|
||||
|
||||
let cache;
|
||||
if (tagsCache) {
|
||||
// @NOTE: exposing cache through getter and setter to not loose the context of "this"
|
||||
cache = {
|
||||
get() {
|
||||
return tagsCache.get(...arguments);
|
||||
},
|
||||
set() {
|
||||
return tagsCache.set(...arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
this.api = {
|
||||
browse: this.tagsPublicRepository.getAll.bind(this.tagsPublicRepository)
|
||||
cache: cache
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue