Skip to content

Commit

Permalink
Merge pull request #581 from RocketChat/bugfix/580
Browse files Browse the repository at this point in the history
Fixes #580.  Undefined statistic when no private group exists
  • Loading branch information
rodrigok committed Aug 26, 2015
2 parents dd44eaa + d713ccd commit 74974ba
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/rocketchat-lib/server/functions/getStatistics.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,24 @@ RocketChat.getStatistics = ->

result = ChatRoom.mapReduce(m, r, { finalize: f, out: "rocketchat_mr_statistics" })

statistics.maxRoomUsers = MapReducedStatistics.findOne({ _id: 1 }).value.max
statistics.avgChannelUsers = MapReducedStatistics.findOne({ _id: 'c' }).value.avg
statistics.avgPrivateGroupUsers = MapReducedStatistics.findOne({ _id: 'p' }).value.avg
statistics.maxRoomUsers = 0
statistics.avgChannelUsers = 0
statistics.avgPrivateGroupUsers = 0

if MapReducedStatistics.findOne({ _id: 1 })
statistics.maxRoomUsers = MapReducedStatistics.findOne({ _id: 1 }).value.max
else
console.log 'max room user statistic not found'.red

if MapReducedStatistics.findOne({ _id: 'c' })
statistics.avgChannelUsers = MapReducedStatistics.findOne({ _id: 'c' }).value.avg
else
console.log 'channel user statistic not found'.red

if MapReducedStatistics.findOne({ _id: 'p' })
statistics.avgPrivateGroupUsers = MapReducedStatistics.findOne({ _id: 'p' }).value.avg
else
console.log 'private group user statistic not found'.red

os = Npm.require('os')
statistics.os =
Expand Down

0 comments on commit 74974ba

Please sign in to comment.