Caching results for channel autocomplete.

pull/954/head
George Secrieru 11 years ago
parent f11b65c9a8
commit 0eeb465d72
  1. 1
      client/lib/collections.coffee
  2. 13
      client/startup/autocomplete.coffee
  3. 14
      client/views/app/messagePopupConfig.coffee
  4. 7
      server/methods/getTotalChannels.coffee
  5. 2
      server/publications/channelAutocomplete.coffee

@ -2,3 +2,4 @@
@ChatRoom = new Meteor.Collection 'rocketchat_room'
@ChatSubscription = new Meteor.Collection 'rocketchat_subscription'
@UserAndRoom = new Meteor.Collection null
@CachedChannelList = new Meteor.Collection null

@ -0,0 +1,13 @@
Meteor.startup ->
Meteor.call 'getTotalChannels', (error, result) ->
if error
return Errors.throw error.reason
# @todo: create settings for limit?
if result <= 200
Meteor.call 'channelsList', (chError, channels) ->
if chError
return Errors.throw chError.reason
CachedChannelList.insert(channel) for channel in channels.channels

@ -2,6 +2,12 @@
@filteredUsers = new Mongo.Collection 'filtered-users'
@channelAutocomplete = new Mongo.Collection 'channel-autocomplete'
channelAutoCompleteCollection = ->
if CachedChannelList.find().count() isnt 0
return CachedChannelList
else
return channelAutocomplete
Template.messagePopupConfig.helpers
popupUserConfig: ->
self = this
@ -50,15 +56,17 @@ Template.messagePopupConfig.helpers
template = Template.instance()
config =
title: 'Channels'
collection: channelAutocomplete
collection: channelAutoCompleteCollection()
trigger: '#'
template: 'messagePopupChannel'
getInput: self.getInput
getFilter: (collection, filter) ->
exp = new RegExp(filter, 'i')
Meteor.subscribe 'channelAutocomplete', filter
items = channelAutocomplete.find( { name: exp }, { limit: 10 }).fetch()
unless _.isEqual(collection, CachedChannelList)
Meteor.subscribe 'channelAutocomplete', filter
items = collection.find( { name: exp }, { limit: 10 }).fetch()
return items
getValue: (_id, collection) ->

@ -0,0 +1,7 @@
Meteor.methods
getTotalChannels: ->
if not Meteor.userId()
throw new Meteor.Error 'invalid-user', '[methods] getTotalChannels -> Invalid user'
console.log '[methods] getTotalChannels -> '.green, 'userId:', Meteor.userId()
return RocketChat.models.Rooms.find({ t: 'c' }).count()

@ -18,7 +18,7 @@ Meteor.publish 'channelAutocomplete', (name) ->
pub = this
cursorHandle = ChatRoom.find(query, options).observeChanges
cursorHandle = RocketChat.models.Rooms.find(query, options).observeChanges
added: (_id, record) ->
pub.added('channel-autocomplete', _id, record)

Loading…
Cancel
Save