mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 19:02:29 +03:00
860718f584
refs #9601 - on resource update/add we have cached mobiledoc, html etc - we have to ensure we exclude the fields (same procdure happens on bootstrap) - these excluded fields don't have to be cached - otherwise memory usage is higher in general - ensure we cache relations with a minimal field set on resource update/add
60 lines
1.2 KiB
JavaScript
60 lines
1.2 KiB
JavaScript
const EventEmitter = require('events').EventEmitter,
|
|
common = require('../../lib/common');
|
|
|
|
class Resource extends EventEmitter {
|
|
constructor(type, obj) {
|
|
super();
|
|
|
|
this.data = {};
|
|
this.config = {
|
|
type: type,
|
|
reserved: false
|
|
};
|
|
|
|
Object.assign(this.data, obj);
|
|
}
|
|
|
|
getType() {
|
|
return this.config.type;
|
|
}
|
|
|
|
reserve() {
|
|
if (!this.config.reserved) {
|
|
this.config.reserved = true;
|
|
} else {
|
|
common.logging.error(new common.errors.InternalServerError({
|
|
message: 'Resource is already taken. This should not happen.',
|
|
code: 'URLSERVICE_RESERVE_RESOURCE'
|
|
}));
|
|
}
|
|
}
|
|
|
|
release() {
|
|
this.config.reserved = false;
|
|
}
|
|
|
|
isReserved() {
|
|
return this.config.reserved === true;
|
|
}
|
|
|
|
update(obj) {
|
|
Object.assign(this.data, obj);
|
|
|
|
if (!this.isReserved()) {
|
|
return;
|
|
}
|
|
|
|
this.emit('updated', this);
|
|
}
|
|
|
|
remove() {
|
|
if (!this.isReserved()) {
|
|
return;
|
|
}
|
|
|
|
this.emit('removed', this);
|
|
}
|
|
}
|
|
|
|
module.exports = Resource;
|