Use generated member count instead of pulling a list of all members from mongo when we get the public clans list.

This commit is contained in:
Rob 2015-11-04 16:00:54 -08:00
parent 34715befcc
commit 75532e3a79
3 changed files with 5 additions and 5 deletions

View file

@ -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')]

View file

@ -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 })

View file

@ -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) =>