Update: User.ad randomize
This commit is contained in:
parent
3ff902353d
commit
7f3b7e936e
1 changed files with 3 additions and 5 deletions
|
|
@ -401,7 +401,7 @@ exports.ad = (req, res) => {
|
||||||
{$sort: {watchedDates: -1}},
|
{$sort: {watchedDates: -1}},
|
||||||
{$limit: limit},
|
{$limit: limit},
|
||||||
{$unwind: '$interest'},
|
{$unwind: '$interest'},
|
||||||
{$group: {_id: null, interests: {$push: '$interest'}}}
|
{$group: {_id: null, interests: {$addToSet: '$interest'}}}
|
||||||
])
|
])
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if(typeof data[0] !== 'undefined' &&
|
if(typeof data[0] !== 'undefined' &&
|
||||||
|
|
@ -410,15 +410,13 @@ exports.ad = (req, res) => {
|
||||||
data[0].interests !== null){
|
data[0].interests !== null){
|
||||||
interests = interests.concat(data[0].interests);
|
interests = interests.concat(data[0].interests);
|
||||||
}
|
}
|
||||||
let match, pick;
|
let match;
|
||||||
if(interests.length > 0){
|
if(interests.length > 0){
|
||||||
match = {$match: {isVisible: true, isActive: true, interests: {$elemMatch: {interest: {$in: interests}}}}};
|
match = {$match: {isVisible: true, isActive: true, interests: {$elemMatch: {interest: {$in: interests}}}}};
|
||||||
pick = {$limit: parseInt(quantity, 10)}
|
|
||||||
} else {
|
} else {
|
||||||
match = {$match: {isVisible: true, isActive: true}};
|
match = {$match: {isVisible: true, isActive: true}};
|
||||||
pick = {$sample: {size: parseInt(quantity, 10)}};
|
|
||||||
}
|
}
|
||||||
|
const pick = {$sample: {size: parseInt(quantity, 10)}};
|
||||||
Ad.aggregate([
|
Ad.aggregate([
|
||||||
match,
|
match,
|
||||||
pick
|
pick
|
||||||
|
|
|
||||||
Reference in a new issue