From 75532e3a79bd3ac0acb569b04416f02069d3abef Mon Sep 17 00:00:00 2001 From: Rob Date: Wed, 4 Nov 2015 16:00:54 -0800 Subject: [PATCH] Use generated member count instead of pulling a list of all members from mongo when we get the public clans list. --- app/templates/clans/clans.jade | 4 ++-- app/views/clans/ClansView.coffee | 4 ++-- server/clans/clan_handler.coffee | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/templates/clans/clans.jade b/app/templates/clans/clans.jade index a0c14444d..e5af78513 100644 --- a/app/templates/clans/clans.jade +++ b/app/templates/clans/clans.jade @@ -40,7 +40,7 @@ block content a(href="/clans/#{clan.id}", style='font-weight:bold')= clan.get('name') else a(href="/clans/#{clan.id}")= clan.get('name') - td= clan.get('members').length + td= clan.get('memberCount') td if idNameMap && idNameMap[clan.get('ownerID')] a(href="/user/#{clan.get('ownerID')}")= idNameMap[clan.get('ownerID')] @@ -70,7 +70,7 @@ block content a(href="/clans/#{clan.id}", style='font-weight:bold')= clan.get('name') else a(href="/clans/#{clan.id}")= clan.get('name') - td= clan.get('members').length + td= clan.get('memberCount') td if idNameMap && idNameMap[clan.get('ownerID')] a(href="/user/#{clan.get('ownerID')}")= idNameMap[clan.get('ownerID')] diff --git a/app/views/clans/ClansView.coffee b/app/views/clans/ClansView.coffee index 0de2c4eec..800a22362 100644 --- a/app/views/clans/ClansView.coffee +++ b/app/views/clans/ClansView.coffee @@ -43,8 +43,8 @@ module.exports = class ClansView extends RootView @idNameMap = {} sortClanList = (a, b) -> - if a.get('members').length isnt b.get('members').length - if a.get('members').length < b.get('members').length then 1 else -1 + if a.get('memberCount') isnt b.get('memberCount') + if a.get('memberCount') < b.get('memberCount') then 1 else -1 else b.id.localeCompare(a.id) @publicClans = new CocoCollection([], { url: '/db/clan/-/public', model: Clan, comparator: sortClanList }) diff --git a/server/clans/clan_handler.coffee b/server/clans/clan_handler.coffee index 58c4a7ec6..50d1e3215 100644 --- a/server/clans/clan_handler.coffee +++ b/server/clans/clan_handler.coffee @@ -143,7 +143,7 @@ ClanHandler = class ClanHandler extends Handler getPublicClans: (req, res) -> # Return 100 public clans, sorted by member count, created date query = [{ $match : {type : 'public'} }] - query.push {$project : {_id: 1, name: 1, slug: 1, type: 1, description: 1, members: 1, memberCount: {$size: "$members"}, ownerID: 1}} + query.push {$project : {_id: 1, name: 1, slug: 1, type: 1, description: 1, memberCount: {$size: "$members"}, ownerID: 1}} query.push {$sort: { memberCount: -1, _id: -1 }} query.push {$limit: 100} Clan.aggregate(query).exec (err, documents) =>