mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Merge pull request #5817 from ErisDS/issue-5810-sqlite
Don't eager load relations on tag update
This commit is contained in:
commit
c57edd67a7
1 changed files with 26 additions and 17 deletions
|
@ -283,27 +283,36 @@ to004 = function to004() {
|
|||
|
||||
// Add post_tag order
|
||||
upgradeOp = function () {
|
||||
return models.Post.findAll(_.extend({}, options, {withRelated: ['tags']})).then(function (posts) {
|
||||
var tagOps = [];
|
||||
var tagOps = [];
|
||||
logInfo('Collecting data on tag order for posts...');
|
||||
return models.Post.findAll(_.extend({}, options)).then(function (posts) {
|
||||
if (posts) {
|
||||
posts.each(function (post) {
|
||||
var order = 0;
|
||||
post.related('tags').each(function (tag) {
|
||||
tagOps.push((function (order) {
|
||||
var sortOrder = order;
|
||||
return function () {
|
||||
return post.tags().updatePivot(
|
||||
{sort_order: sortOrder}, _.extend({}, options, {query: {where: {tag_id: tag.id}}})
|
||||
);
|
||||
};
|
||||
}(order)));
|
||||
order += 1;
|
||||
});
|
||||
return posts.mapThen(function (post) {
|
||||
return post.load(['tags']);
|
||||
});
|
||||
}
|
||||
return [];
|
||||
}).then(function (posts) {
|
||||
_.each(posts, function (post) {
|
||||
var order = 0;
|
||||
post.related('tags').each(function (tag) {
|
||||
tagOps.push((function (order) {
|
||||
var sortOrder = order;
|
||||
return function () {
|
||||
return post.tags().updatePivot(
|
||||
{sort_order: sortOrder}, _.extend({}, options, {query: {where: {tag_id: tag.id}}})
|
||||
);
|
||||
};
|
||||
}(order)));
|
||||
order += 1;
|
||||
});
|
||||
});
|
||||
|
||||
if (tagOps.length > 0) {
|
||||
logInfo('Updating order on ' + tagOps.length + ' tags');
|
||||
return sequence(tagOps);
|
||||
logInfo('Updating order on ' + tagOps.length + ' tag relationships (could take a while)...');
|
||||
return sequence(tagOps).then(function () {
|
||||
logInfo('Tag order successfully updated');
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue