mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-15 03:01:37 -05:00
Fixed maximum call stack exceeded error when filtering Action events
- after a while of browsing around filtering Actions, the endpoint will suddenly lock up and start throwing stack exceeded errors - this is because every time we initialize an Actions model, we push to the `candidates` array with a list of the current models - this was producing a `candidates` array with a length of several thousand models after a few clicks, which would cause errors when joining the data down the line - the code was like this because we need to lazy-initialize the models, so the order of requiring the Actions model doesn't matter - this commit switches the code to using a `candidates` function to get the models - this seems to work and the performance cost is negligible given it now doesn't error
This commit is contained in:
parent
05e32b3ea5
commit
2c60340a7d
1 changed files with 6 additions and 9 deletions
|
@ -1,24 +1,21 @@
|
|||
const _ = require('lodash');
|
||||
const ghostBookshelf = require('./base');
|
||||
|
||||
const candidates = [];
|
||||
|
||||
const Action = ghostBookshelf.Model.extend({
|
||||
tableName: 'actions',
|
||||
|
||||
initialize: function initialize() {
|
||||
_.each(ghostBookshelf.registry.models, (model) => {
|
||||
candidates.push([model, model.prototype.tableName.replace(/s$/, '')]);
|
||||
candidates() {
|
||||
return Object.keys(ghostBookshelf.registry.models).map((key) => {
|
||||
const model = ghostBookshelf.registry.models[key];
|
||||
return [model, model.prototype.tableName.replace(/s$/, '')];
|
||||
});
|
||||
this.constructor.__super__.initialize.apply(this, arguments);
|
||||
},
|
||||
|
||||
actor() {
|
||||
return this.morphTo('actor', ['actor_type', 'actor_id'], ...candidates);
|
||||
return this.morphTo('actor', ['actor_type', 'actor_id'], ...this.candidates());
|
||||
},
|
||||
|
||||
resource() {
|
||||
return this.morphTo('resource', ['resource_type', 'resource_id'], ...candidates);
|
||||
return this.morphTo('resource', ['resource_type', 'resource_id'], ...this.candidates());
|
||||
}
|
||||
}, {
|
||||
orderDefaultOptions: function orderDefaultOptions() {
|
||||
|
|
Loading…
Add table
Reference in a new issue