Class: Workarea::User::AdminVisit

Inherits:
Object
  • Object
show all
Includes:
ApplicationDocument
Defined in:
app/models/workarea/user/admin_visit.rb

Class Method Summary collapse

Methods included from ApplicationDocument

#releasable?

Methods included from Sidekiq::Callbacks

add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list

Methods included from Mongoid::Document

#embedded_children

Class Method Details

.most_visited(user_id, limit = Workarea.config.admin_max_most_visited) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/workarea/user/admin_visit.rb', line 13

def self.most_visited(user_id, limit = Workarea.config.admin_max_most_visited)
  results = collection.aggregate([
    {
      '$match' => { 'user_id' => user_id.to_s }
    },
    {
      '$group' => {
        '_id' => '$path',
        'name' => { '$first' => '$name' },
        'count' => { '$sum' => 1 }
      }
    },
    {
      '$sort' => { 'count' => -1 }
    },
    {
      '$limit' => limit
    }
  ])

  results.map do |result|
    { name: result['name'], path: result['_id'] }
  end
end