mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
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:
parent
34715befcc
commit
75532e3a79
3 changed files with 5 additions and 5 deletions
|
@ -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')]
|
||||
|
|
|
@ -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 })
|
||||
|
|
|
@ -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) =>
|
||||
|
|
Loading…
Reference in a new issue