Skip to content

Commit

Permalink
Merge 1006127 into c1c64c2
Browse files Browse the repository at this point in the history
  • Loading branch information
TildaDares authored Jun 11, 2021
2 parents c1c64c2 + 1006127 commit f3e816e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/assets/javascripts/atWhoAutoComplete.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
(function() {

// settings at https://github.com/ichord/At.js/wiki/Base-Document#settings

// checks if the 'name' key in the JSON data is named 'username' or 'name' and then returns the
// correct key-value
const displayName = (item) => item.username ? item.username : item.name;

var at_config = {
at: "@",
displayTpl: (item) => `<li>${displayName(item)}</li>`,
insertTpl: (item) => `@${displayName(item)}`,
// loads and saves remote JSON data by URL
data: '/users/active',
delay: 400,
callbacks: {
remoteFilter: debounce(function(query, callback) {
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ def verify_email
redirect_to "/login", flash: { notice: action_msg }
end

def recently_active_users
active_users = User.recently_active_users
render json: active_users, root: false
end

private

def subscribe_multiple_tag(tag_list)
Expand Down
12 changes: 12 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,18 @@ def latest_location
recent_locations.last
end

def self.recently_active_users(limit = 5, order = 'last_updated DESC')
Rails.cache.fetch('users/active', expires_in: 24.hours) do
User.select('rusers.username, rusers.status, rusers.id, MAX(node_revisions.timestamp) AS last_updated')
.joins("INNER JOIN `node_revisions` ON `node_revisions`.`uid` = `rusers`.`id` ")
.where("node_revisions.status = 1")
.where("rusers.status = 1")
.group('rusers.id')
.order(order)
.limit(limit)
end
end

private

def decrease_likes_banned
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
get 'signup' => 'users#new'
get 'home' => 'home#front'
get 'verify/:token' => 'users#verify_email'
get 'users/active' => 'users#recently_active_users'
resources :relationships, only: [:create, :destroy]

get '/wiki/:id/comments', to: 'wiki#comments'
Expand Down

0 comments on commit f3e816e

Please sign in to comment.