Speed up clan details page

Only fetch level sessions and achievements for 200 members.
Display members with more data first.
Show average clan achievements instead of total achievements.
General css cleanup.
This commit is contained in:
Matt Lott 2015-04-20 16:20:49 -07:00
parent 9466923013
commit c9a7f6773d
4 changed files with 41 additions and 19 deletions
app
styles/clans
templates/clans
views/clans
server/clans

View file

@ -7,7 +7,7 @@
font-weight: bold
.stats-table
width: 240px
width: 400px
background: rgba(0, 0, 0, 0.0)
#editDescriptionModal .modal-dialog
@ -35,9 +35,18 @@
.level-cell
width: 50px
text-align: center
vertical-align: middle
.name-cell
width: 100px
vertical-align: middle
.achievements-cell
text-align: center
vertical-align: middle
.latest-achievement-cell
vertical-align: middle
.level-progression-cell
background-color: lightblue
@ -55,8 +64,7 @@
font-size: 10pt
.level-progression-cell-name
background-color: lightblue
border: 1px solid gray
vertical-align: middle
.player-hero-icon
background: transparent url(/images/pages/play/play-spritesheet.png)
@ -66,6 +74,7 @@
width: 30px
height: 30px
margin: 0px 2px
vertical-align: middle
.player-hero-icon
background-position: (-4 * $spriteSheetSize) 0

View file

@ -54,10 +54,10 @@ block content
tr
td Average Level
td= stats.averageLevel
if stats.totalAchievements && clan.get('type') === 'public'
if stats.averageAchievements && clan.get('type') === 'public'
tr
td Total Achievements
td= stats.totalAchievements
td Average Achievements
td= stats.averageAchievements
p
if isOwner
@ -83,8 +83,8 @@ block content
th
th
th
th Level
th Name
th.level-cell Level
th.name-cell Name
th(colspan="#{memberMaxLevelCount + 1}") Last Level Completed
tbody
each member in members
@ -108,7 +108,7 @@ block content
div Level: #{levelInfo.level}
div Playtime: #{levelInfo.playtime}
div Last played: #{levelInfo.changed}
td(colspan="#{memberMaxLevelCount - memberLevelProgression[member.id].length + 1}")= memberLevelProgression[member.id][memberLevelProgression[member.id].length - 1].level
td.level-progression-cell-name(colspan="#{memberMaxLevelCount - memberLevelProgression[member.id].length + 1}")= memberLevelProgression[member.id][memberLevelProgression[member.id].length - 1].level
else
td(colspan="#{memberMaxLevelCount + 1}")
else
@ -117,10 +117,10 @@ block content
tr
th
th
td Name
th Level
th Achievements
th Latest Achievement
td.name-cell Name
th.level-cell Level
th.achievements-cell Achievements
th.latest-achievement-cell Latest Achievement
th
tbody
each member in members
@ -130,13 +130,13 @@ block content
td.code-language-cell
if memberLanguageMap && memberLanguageMap[member.id]
span.code-language-cell(style="background-image: url(/images/common/code_languages/#{memberLanguageMap[member.id]}_small.png)", title=memberLanguageMap[member.id])
td
td.name-cell
a(href="/user/#{member.id}")= member.get('name') || 'Anoner'
td= member.level()
td
td.level-cell= member.level()
td.achievements-cell
if memberAchievementsMap && memberAchievementsMap[member.id]
| #{memberAchievementsMap[member.id].length}
td
td.latest-achievement-cell
if memberAchievementsMap && memberAchievementsMap[member.id] && memberAchievementsMap[member.id].length
span= memberAchievementsMap[member.id][0].get('achievementName')
td

View file

@ -67,6 +67,15 @@ module.exports = class ClanDetailsView extends RootView
context.memberLevelProgression = @memberLevelProgression
context.memberMaxLevelCount = @memberMaxLevelCount
context.members = @members?.models
# Give preference to members with more data
if @memberLevelProgression? and @memberLanguageMap?
context.members.sort (a, b) =>
if a.id of @memberLevelProgression and a.id of @memberLanguageMap
-1
else if b.id of @memberLevelProgression and b.id of @memberLanguageMap
1
else
0
context.isOwner = @clan.get('ownerID') is me.id
context.isMember = @clanID in (me.get('clans') ? [])
context.stats = @stats
@ -101,7 +110,6 @@ module.exports = class ClanDetailsView extends RootView
@render?()
onMemberAchievementsSync: ->
@stats.totalAchievements = @memberAchievements.models.length
@memberAchievementsMap = {}
for achievement in @memberAchievements.models
user = achievement.get('user')
@ -109,6 +117,7 @@ module.exports = class ClanDetailsView extends RootView
@memberAchievementsMap[user].push achievement
for user of @memberAchievementsMap
@memberAchievementsMap[user].sort (a, b) -> b.id.localeCompare(a.id)
@stats.averageAchievements = Math.round(@memberAchievements.models.length / Object.keys(@memberAchievementsMap).length)
@render?()
onMemberSessionsSync: ->

View file

@ -98,10 +98,12 @@ ClanHandler = class ClanHandler extends Handler
getMemberAchievements: (req, res, clanID) ->
# TODO: add tests
memberLimit = 200
Clan.findById clanID, (err, clan) =>
return @sendDatabaseError(res, err) if err
return @sendNotFoundError(res) unless clan
memberIDs = _.map clan.get('members') ? [], (memberID) -> memberID.toHexString?() or memberID
memberIDs = memberIDs.slice 0, memberLimit
EarnedAchievement.find {user: {$in: memberIDs}}, 'achievementName user', (err, documents) =>
return @sendDatabaseError(res, err) if err?
cleandocs = (EarnedAchievementHandler.formatEntity(req, doc) for doc in documents)
@ -121,10 +123,12 @@ ClanHandler = class ClanHandler extends Handler
getMemberSessions: (req, res, clanID) ->
# TODO: add tests
# TODO: restrict information returned based on clan type
memberLimit = 200
Clan.findById clanID, (err, clan) =>
return @sendDatabaseError(res, err) if err
return @sendNotFoundError(res) unless clan
memberIDs = _.map clan.get('members') ? [], (memberID) -> memberID.toHexString?() or memberID
memberIDs = _.map clan.get('members') ? [], (memberID) -> memberID.toHexString?() or memberID
memberIDs = memberIDs.slice 0, memberLimit
LevelSession.find {creator: {$in: memberIDs}}, 'changed codeLanguage creator creatorName levelName playtime state submittedCodeLanguage', (err, documents) =>
return @sendDatabaseError(res, err) if err?
cleandocs = (LevelSessionHandler.formatEntity(req, doc) for doc in documents)