I can't figure out why get_raw_records is called three times when my controller calling it is only called once. The table is only fetched once as shown below in the console but the get_raw_records method is called 3 times...
datatable_in_question
class FindVoterFriendsDatatable < ApplicationDatatable
extend Forwardable
def_delegators :@view, :link_to, :edit_user_path, :voter_friends_path, :params, :check_box_tag
def get_raw_records
puts "Getting raw records"
voters = Voter.none
end
def initialize(params, opts = {})
@view = opts[:view_context]
super
end
end
#controller that calls it
#This is the voter search table to add voter_friends
def index
respond_to do |format|
format.html
format.json { render json: FindVoterFriendsDatatable.new(params, view_context: view_context) }
end
end
Console:
Started GET "/voter/friends" for ::1 at 2020-07-20 15:14:32 -0400
Processing by Voter::FriendsController#index as HTML
/Users/brian/.rvm/gems/ruby-2.7.1/gems/json-2.2.0/lib/json/common.rb:156: warning: Using the last argument as keyword parameters is deprecated
/Users/brian/.rvm/gems/ruby-2.7.1/gems/activerecord-5.1.7/lib/active_record/statement_cache.rb:90: warning: Capturing the given block using Proc.new is deprecated; use &block instead
User Load (0.3ms) SELECT "users". FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 48], ["LIMIT", 1]]
Rendering voter/friends/index.html.slim within layouts/application
(0.8ms) SELECT COUNT() FROM "voters" INNER JOIN "voter_friends" ON "voters"."id" = "voter_friends"."voter_id" WHERE "voter_friends"."user_id" = $1 [["user_id", 48]]
Rendered voter/friends/index.html.slim within layouts/application (38.3ms)
Rendered layouts/_header.html.slim (6.5ms)
/Users/brian/.rvm/gems/ruby-2.7.1/gems/activerecord-5.1.7/lib/active_record/statement_cache.rb:90: warning: Capturing the given block using Proc.new is deprecated; use &block instead
User::Privilege Load (0.3ms) SELECT "user_privileges".* FROM "user_privileges" WHERE "user_privileges"."user_id" = $1 LIMIT $2 [["user_id", 48], ["LIMIT", 1]]
Rendered layouts/_left_panel.html.erb (29.1ms)
Rendered layouts/_footer.html.slim (2.8ms)
Rendered layouts/_tiles.html.slim (3.8ms)
Rendered layouts/_scripts.html.erb (0.3ms)
Rendered layouts/_flash_messages.html.slim (9.3ms)
Completed 200 OK in 228ms (Views: 176.9ms | ActiveRecord: 11.0ms)
Started GET "/voter/friends.json?draw=1&columns%5B0%5D%5Bdata%5D=friend&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=false&columns%5B0%5D%5Borderable%5D=false&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=full_name&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Borderable%5D=false&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=full_address&columns%5B2%5D%5Bname%5D=&columns%5B2%5D%5Bsearchable%5D=false&columns%5B2%5D%5Borderable%5D=false&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B3%5D%5Bdata%5D=party&columns%5B3%5D%5Bname%5D=&columns%5B3%5D%5Bsearchable%5D=false&columns%5B3%5D%5Borderable%5D=false&columns%5B3%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B3%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B4%5D%5Bdata%5D=birthdate&columns%5B4%5D%5Bname%5D=&columns%5B4%5D%5Bsearchable%5D=false&columns%5B4%5D%5Borderable%5D=false&columns%5B4%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B4%5D%5Bsearch%5D%5Bregex%5D=false&order%5B0%5D%5Bcolumn%5D=0&order%5B0%5D%5Bdir%5D=asc&start=0&length=100&search%5Bvalue%5D=&search%5Bregex%5D=false&cityfilter=&=1595272472959" for ::1 at 2020-07-20 15:14:33 -0400
Processing by Voter::FriendsController#index as JSON
Parameters: {"draw"=>"1", "columns"=>{"0"=>{"data"=>"friend", "name"=>"", "searchable"=>"false", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}}, "1"=>{"data"=>"full_name", "name"=>"", "searchable"=>"true", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}}, "2"=>{"data"=>"full_address", "name"=>"", "searchable"=>"false", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}}, "3"=>{"data"=>"party", "name"=>"", "searchable"=>"false", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}}, "4"=>{"data"=>"birthdate", "name"=>"", "searchable"=>"false", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}}}, "order"=>{"0"=>{"column"=>"0", "dir"=>"asc"}}, "start"=>"0", "length"=>"100", "search"=>{"value"=>"", "regex"=>"false"}, "cityfilter"=>"", ""=>"1595272472959"}
/Users/brian/.rvm/gems/ruby-2.7.1/gems/json-2.2.0/lib/json/common.rb:156: warning: Using the last argument as keyword parameters is deprecated
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 48], ["LIMIT", 1]]
Getting raw records
Getting raw records
Getting raw records
Completed 200 OK in 16ms (Views: 5.8ms | ActiveRecord: 0.5ms)
I can't figure out why get_raw_records is called three times when my controller calling it is only called once. The table is only fetched once as shown below in the console but the get_raw_records method is called 3 times...
datatable_in_question
#controller that calls it
Console: Started GET "/voter/friends" for ::1 at 2020-07-20 15:14:32 -0400 Processing by Voter::FriendsController#index as HTML /Users/brian/.rvm/gems/ruby-2.7.1/gems/json-2.2.0/lib/json/common.rb:156: warning: Using the last argument as keyword parameters is deprecated /Users/brian/.rvm/gems/ruby-2.7.1/gems/activerecord-5.1.7/lib/active_record/statement_cache.rb:90: warning: Capturing the given block using Proc.new is deprecated; use
&block
instead User Load (0.3ms) SELECT "users". FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 48], ["LIMIT", 1]] Rendering voter/friends/index.html.slim within layouts/application (0.8ms) SELECT COUNT() FROM "voters" INNER JOIN "voter_friends" ON "voters"."id" = "voter_friends"."voter_id" WHERE "voter_friends"."user_id" = $1 [["user_id", 48]] Rendered voter/friends/index.html.slim within layouts/application (38.3ms) Rendered layouts/_header.html.slim (6.5ms) /Users/brian/.rvm/gems/ruby-2.7.1/gems/activerecord-5.1.7/lib/active_record/statement_cache.rb:90: warning: Capturing the given block using Proc.new is deprecated; use&block
instead User::Privilege Load (0.3ms) SELECT "user_privileges".* FROM "user_privileges" WHERE "user_privileges"."user_id" = $1 LIMIT $2 [["user_id", 48], ["LIMIT", 1]] Rendered layouts/_left_panel.html.erb (29.1ms) Rendered layouts/_footer.html.slim (2.8ms) Rendered layouts/_tiles.html.slim (3.8ms) Rendered layouts/_scripts.html.erb (0.3ms) Rendered layouts/_flash_messages.html.slim (9.3ms) Completed 200 OK in 228ms (Views: 176.9ms | ActiveRecord: 11.0ms)Started GET "/voter/friends.json?draw=1&columns%5B0%5D%5Bdata%5D=friend&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=false&columns%5B0%5D%5Borderable%5D=false&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=full_name&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Borderable%5D=false&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=full_address&columns%5B2%5D%5Bname%5D=&columns%5B2%5D%5Bsearchable%5D=false&columns%5B2%5D%5Borderable%5D=false&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B3%5D%5Bdata%5D=party&columns%5B3%5D%5Bname%5D=&columns%5B3%5D%5Bsearchable%5D=false&columns%5B3%5D%5Borderable%5D=false&columns%5B3%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B3%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B4%5D%5Bdata%5D=birthdate&columns%5B4%5D%5Bname%5D=&columns%5B4%5D%5Bsearchable%5D=false&columns%5B4%5D%5Borderable%5D=false&columns%5B4%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B4%5D%5Bsearch%5D%5Bregex%5D=false&order%5B0%5D%5Bcolumn%5D=0&order%5B0%5D%5Bdir%5D=asc&start=0&length=100&search%5Bvalue%5D=&search%5Bregex%5D=false&cityfilter=&=1595272472959" for ::1 at 2020-07-20 15:14:33 -0400 Processing by Voter::FriendsController#index as JSON Parameters: {"draw"=>"1", "columns"=>{"0"=>{"data"=>"friend", "name"=>"", "searchable"=>"false", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}}, "1"=>{"data"=>"full_name", "name"=>"", "searchable"=>"true", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}}, "2"=>{"data"=>"full_address", "name"=>"", "searchable"=>"false", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}}, "3"=>{"data"=>"party", "name"=>"", "searchable"=>"false", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}}, "4"=>{"data"=>"birthdate", "name"=>"", "searchable"=>"false", "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}}}, "order"=>{"0"=>{"column"=>"0", "dir"=>"asc"}}, "start"=>"0", "length"=>"100", "search"=>{"value"=>"", "regex"=>"false"}, "cityfilter"=>"", ""=>"1595272472959"} /Users/brian/.rvm/gems/ruby-2.7.1/gems/json-2.2.0/lib/json/common.rb:156: warning: Using the last argument as keyword parameters is deprecated User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 48], ["LIMIT", 1]] Getting raw records Getting raw records Getting raw records Completed 200 OK in 16ms (Views: 5.8ms | ActiveRecord: 0.5ms)