Fix “Authorized applications” inefficiently and incorrectly getting last use date (#25060)
This commit is contained in:
		@@ -9,6 +9,8 @@ class Oauth::AuthorizedApplicationsController < Doorkeeper::AuthorizedApplicatio
 | 
			
		||||
  before_action :set_body_classes
 | 
			
		||||
  before_action :set_cache_headers
 | 
			
		||||
 | 
			
		||||
  before_action :set_last_used_at_by_app, only: :index, unless: -> { request.format == :json }
 | 
			
		||||
 | 
			
		||||
  skip_before_action :require_functional!
 | 
			
		||||
 | 
			
		||||
  include Localized
 | 
			
		||||
@@ -35,4 +37,14 @@ class Oauth::AuthorizedApplicationsController < Doorkeeper::AuthorizedApplicatio
 | 
			
		||||
  def set_cache_headers
 | 
			
		||||
    response.cache_control.replace(private: true, no_store: true)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def set_last_used_at_by_app
 | 
			
		||||
    @last_used_at_by_app = Doorkeeper::AccessToken
 | 
			
		||||
                           .select('DISTINCT ON (application_id) application_id, last_used_at')
 | 
			
		||||
                           .where(resource_owner_id: current_resource_owner.id)
 | 
			
		||||
                           .where.not(last_used_at: nil)
 | 
			
		||||
                           .order(application_id: :desc, last_used_at: :desc)
 | 
			
		||||
                           .pluck(:application_id, :last_used_at)
 | 
			
		||||
                           .to_h
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user