Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit 7ae6156

Browse files
committed
limit single item populates to 1 / remove population in emotion hook
1 parent 16edec6 commit 7ae6156

File tree

8 files changed

+48
-21
lines changed

8 files changed

+48
-21
lines changed

server/seeder/development/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = function () {
1212
require('./candos'),
1313
require('./users-candos'),
1414
require('./projects'),
15-
// require('./follows'),
15+
require('./follows'),
1616
require('./comments'),
1717
require('./emotions'),
1818
require('./invites'),

server/services/comments/comments.hooks.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ const userSchema = {
2121
service: 'users',
2222
nameAs: 'user',
2323
parentField: 'userId',
24-
childField: '_id'
24+
childField: '_id',
25+
query: {
26+
$limit: 1
27+
}
2528
}
2629
};
2730

server/services/contributions/contributions.hooks.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ const userSchema = {
2626
service: 'users',
2727
nameAs: 'user',
2828
parentField: 'userId',
29-
childField: '_id'
29+
childField: '_id',
30+
query: {
31+
$limit: 1
32+
}
3033
}
3134
};
3235

server/services/emotions/hooks/emotion-rating.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,21 @@ module.exports = function(options = {}) { // eslint-disable-line no-unused-vars
5656
});
5757
putQuery.$inc[`emotions.${hook.result.rated}.count`] += 1;
5858

59-
contributionService.patch( hook.result.contributionId, putQuery)
60-
.then(contribution => {
59+
contributionService.patch(
60+
hook.result.contributionId,
61+
putQuery,
62+
{ _populate: 'skip' }
63+
).then(contribution => {
64+
calculatePercentValues(contribution);
6165

62-
calculatePercentValues(contribution);
63-
64-
contributionService.patch( hook.result.contributionId, {
65-
$set: {
66-
emotions: contribution.emotions
67-
}
68-
}).then(() => {
69-
resolve(hook);
70-
});
66+
contributionService.patch( hook.result.contributionId, {
67+
$set: {
68+
emotions: contribution.emotions
69+
}
70+
}).then(() => {
71+
resolve(hook);
7172
});
73+
});
7274
});
7375
});
7476
};

server/services/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const badges = require('./badges/badges.service.js');
1212
const emotions = require('./emotions/emotions.service.js');
1313
const organizations = require('./organizations/organizations.service.js');
1414
const projects = require('./projects/projects.service.js');
15-
// const follows = require('./follows/follows.service.js');
15+
const follows = require('./follows/follows.service.js');
1616
const shouts = require('./shouts/shouts.service.js');
1717
const admin = require('./admin/admin.service.js');
1818
const invites = require('./invites/invites.service.js');
@@ -38,7 +38,7 @@ module.exports = function () {
3838
app.configure(emotions);
3939
app.configure(organizations);
4040
app.configure(projects);
41-
// app.configure(follows);
41+
app.configure(follows);
4242
app.configure(shouts);
4343
app.configure(admin);
4444
app.configure(invites);

server/services/notifications/notifications.hooks.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@ const commentSchema = {
1313
nameAs: 'comment',
1414
parentField: 'relatedCommentId',
1515
childField: '_id',
16+
query: {
17+
$limit: 1
18+
},
1619
include: {
1720
service: 'users',
1821
nameAs: 'user',
1922
parentField: 'userId',
20-
childField: '_id'
23+
childField: '_id',
24+
query: {
25+
$limit: 1
26+
}
2127
}
2228
}
2329
};
@@ -27,7 +33,10 @@ const contributionSchema = {
2733
service: 'contributions',
2834
nameAs: 'contribution',
2935
parentField: 'relatedContributionId',
30-
childField: '_id'
36+
childField: '_id',
37+
query: {
38+
$limit: 1
39+
}
3140
}
3241
};
3342

@@ -36,7 +45,10 @@ const userSchema = {
3645
service: 'users',
3746
nameAs: 'user',
3847
parentField: 'relatedUserId',
39-
childField: '_id'
48+
childField: '_id',
49+
query: {
50+
$limit: 1
51+
}
4052
}
4153
};
4254

server/services/organizations/organizations.hooks.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ const reviewerSchema = {
3232
service: 'users',
3333
nameAs: 'reviewer',
3434
parentField: 'reviewedBy',
35-
childField: '_id'
35+
childField: '_id',
36+
query: {
37+
$limit: 1
38+
}
3639
}
3740
};
3841

server/services/users/users.hooks.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ const userSettingsPrivateSchema = {
5858
nameAs: 'userSettings',
5959
parentField: '_id',
6060
childField: 'userId',
61-
asArray: false
61+
asArray: false,
62+
query: {
63+
$limit: 1
64+
}
6265
}
6366
};
6467

@@ -70,6 +73,7 @@ const userSettingsSchema = {
7073
childField: 'userId',
7174
query: {
7275
$select: ['uiLanguage', 'contentLanguages'],
76+
$limit: 1
7377
},
7478
asArray: false
7579
}

0 commit comments

Comments
 (0)