Skip to content

Instantly share code, notes, and snippets.

@VictorTpo
Last active January 21, 2016 09:26
Show Gist options
  • Save VictorTpo/1bdfeb88062b6f5a23d3 to your computer and use it in GitHub Desktop.
Save VictorTpo/1bdfeb88062b6f5a23d3 to your computer and use it in GitHub Desktop.
class RelationshipAnalyzesController < ApplicationController
  def show
    @search = @analyze.search_results(params)
    @results = @search.results.map { |result| AnalyzeResultPresenter.new(result) }
  end
end
class AnalyzeResult < ActiveRecord::Base
  searchable do
    #...
  end
  
  def search_results
    RelationshipAnalyzeResult.solr_search do
      #...
    end
  end
end
class AnalyzeResultPresenter
  def initialize(relationship_analyze_result)
    tw_computing = analyze_result.analyze.brand.twitter_id.present? ? 'En cours' : '-'
    fb_computing = analyze_result.analyze.brand.facebook_id.present? ? 'En cours' : '-'
    #...
    @celebrity  = analyze_result.celebrity
  end
end

LOGS :

  • 106 lines
  • 105 SELECT requests
  • Complete in 1106ms

include, bicth

def search_results
  RelationshipAnalyzeResult.solr_search(include: %i(celebrity brand)) do
    #...
  end
end

LOGS :

  • 19 lines
  • 18 SELECT requests
  • Complete in 553ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment