Skip to content

Commit

Permalink
Remove empty groups (#1580)
Browse files Browse the repository at this point in the history
* Tested on dev and it zapped every empty group there during this period.
* Make a more reasonable period for dev vs pro. Waiting 2 hours shouldn't be needed... set to 60 seconds in dev.

Applies to #83 

Auto-merge
  • Loading branch information
Martii authored Feb 5, 2019
1 parent 69e99bc commit ffa194b
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions libs/modelParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ var parseGroup = function (aGroup) {

// Wait two hours between group rating updates
// This calculation runs in the background
if (new Date().getTime() > (group.updated.getTime() + 1000 * 60 * 60 * 2)) {
if (new Date().getTime() > (group.updated.getTime() + (isPro ? 1000 * 60 * 60 * 2 : 1000 * 60))) {
Script.find({
_id: { $in: group._scriptIds }
}, function (aErr, aScripts) {
Expand All @@ -575,16 +575,29 @@ var parseGroup = function (aGroup) {
group.rating = getRating(aScripts);
}

group.updated = new Date();
group.save(function (aErr, aGroup) {
if (aErr || !aGroup) {
console.error('Group rating NOT updated', 'aErr := ' + aErr, 'aGroup := ' + aGroup);
return;
}
if (isDbg) {
console.log(util.format('Group(%s) rating updated', aGroup.name));
}
});
if (aScripts && aScripts.length === 0) {
group.remove(function (aErr, aGroup) {
if (aErr) {
console.error('Error removing empty group', 'aErr := ' + aErr, 'aGroup := ' + aGroup);
return;
}
if (isDbg) {
console.log(util.format('Empty Group(%s) removed', aGroup.name));
}
});

} else {
group.updated = new Date();
group.save(function (aErr, aGroup) {
if (aErr || !aGroup) {
console.error('Group rating NOT updated', 'aErr := ' + aErr, 'aGroup := ' + aGroup);
return;
}
if (isDbg) {
console.log(util.format('Group(%s) rating updated', aGroup.name));
}
});
}
});
}

Expand Down

1 comment on commit ffa194b

@Martii
Copy link
Member Author

@Martii Martii commented on ffa194b Feb 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#93 instead

Please sign in to comment.