Skip to content
Snippets Groups Projects
Commit d713ccd0 authored by Reid Wakida's avatar Reid Wakida
Browse files

Fixes #580. Checks if statistic is defined in collection before setting

value.  Defaults to 0, if statistic not found and logs message in case statistic
should exist (e.g. if schema changes and map/reduce function is incorrect).
parent dd44eaa5
No related branches found
No related tags found
No related merge requests found
...@@ -46,9 +46,24 @@ RocketChat.getStatistics = -> ...@@ -46,9 +46,24 @@ RocketChat.getStatistics = ->
result = ChatRoom.mapReduce(m, r, { finalize: f, out: "rocketchat_mr_statistics" }) result = ChatRoom.mapReduce(m, r, { finalize: f, out: "rocketchat_mr_statistics" })
statistics.maxRoomUsers = MapReducedStatistics.findOne({ _id: 1 }).value.max statistics.maxRoomUsers = 0
statistics.avgChannelUsers = MapReducedStatistics.findOne({ _id: 'c' }).value.avg statistics.avgChannelUsers = 0
statistics.avgPrivateGroupUsers = MapReducedStatistics.findOne({ _id: 'p' }).value.avg 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') os = Npm.require('os')
statistics.os = statistics.os =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment