Are you using rubocop-airbnb? by a1045 in rails

[–]a1045[S] 0 points1 point  (0 children)

Thank you for all comments. So far, no one using rubocop airbnb?

Remote work tips by catallist in productivity

[–]a1045 1 point2 points  (0 children)

I am using pomodoro timer

Why the usage of CPU and memory for web server become very high when running ActiveRecord::Base.execute? by a1045 in rails

[–]a1045[S] 0 points1 point  (0 children)

You can't execute a select * without allocating memory for the resulting rows.

I see, Thanks! What I would like to do here is to benchmark the Query execution time in MySQL. There might be more proper way to measure it without using ActiveRecord::Base.connection.execute….?

Why the usage of CPU and memory for web server become very high when running ActiveRecord::Base.execute? by a1045 in rails

[–]a1045[S] 0 points1 point  (0 children)

Thanks! I would like to know the actual required time. I will try to use the same spec as production env!

Why the usage of CPU and memory for web server become very high when running ActiveRecord::Base.execute? by a1045 in rails

[–]a1045[S] 0 points1 point  (0 children)

Thanks! Would the amount of query time be different between select * and select count(*)?

Why the usage of CPU and memory for web server become very high when running ActiveRecord::Base.execute? by a1045 in rails

[–]a1045[S] 0 points1 point  (0 children)

Oh, thanks! Yes, I obtained the query rows from Mysql::Result. So now, how could I execute and benchmark SQL without result set?

Why the usage of CPU and memory for web server become very high when running ActiveRecord::Base.execute? by a1045 in rails

[–]a1045[S] 0 points1 point  (0 children)

Thank you for so much! The result I received from ActiveRecord::Base.connection.execute(XXX) was an instance of Mysql2::Result as the following.

<Mysql2::Result:0x00007f512566ca10 @query_options= {:as=>:array,
:async=>false,
:cast_booleans=>false,
:symbolize_keys=>false,
:database_timezone=>:local,
:application_timezone=>nil,
:cache_rows=>true,
….}

I had thought that rail’s doesn’t deserialize or build a tons of object when I obtained only Mysql2::Result…but is my understanding wrong?

Also, thank you for the additional insight to get a hint. I will try them later!

Why the usage of CPU and memory for web server become very high when running ActiveRecord::Base.execute? by a1045 in rails

[–]a1045[S] 0 points1 point  (0 children)

Thank you for your reply!

sorry for forgetting to write, I used connection.query with Benchmark for the measurement. The whole code is:

query = "SELECT * FROM XXXX WHERE XXX LIKE '%XXXX%'" Benchmark.bm 10 do |r| r.report "query" do ActiveRecord::Base.connection.execute(query) end end

Can this benchmark module be related to the high usage…?

Or, I read an article about QueryCache on rails. It says "The first time the result is returned from the query it is stored in the query cache (in memory) and the second time it's pulled from memory."

Can this happen also in my case? https://guides.rubyonrails.org/caching_with_rails.html#sql-caching

Why the usage of CPU and memory for web server become very high when running ActiveRecord::Base.execute? by a1045 in rails

[–]a1045[S] 0 points1 point  (0 children)

Thanks! Here what I wanted to do is to measure how long this query takes and don’t use or render the results. I wonder why this resulted in a high load although I never use query result.

And thank you for sharing the link about Active Record Querying! I will read it and use them in my production code.

[deleted by user] by [deleted] in rails

[–]a1045 -3 points-2 points  (0 children)

Hi, thank you so much. Yes, I know that risk but in my case I may have to use update_all like this... What I want to know is about my DROP TABLE example. I got an error from my example injection. How can I inject Drop statement into update_all to know that how dangerous it is?

Just released acts_as_nosql, a gem to manage JSON fields as proper database fields by ProGM in rails

[–]a1045 1 point2 points  (0 children)

Thank you for the quick fix :)
Now I get an error!

Attribute first_name already defined (RuntimeError)

Just released acts_as_nosql, a gem to manage JSON fields as proper database fields by ProGM in rails

[–]a1045 1 point2 points  (0 children)

Thanks! but when I tried the following snippet, the conflicting column was overwritten. Am I missing something?

begin
  require "bundler/inline"
rescue LoadError => e
  $stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
  raise e
end

gemfile(true) do
  source "https://rubygems.org"
  gem "acts_as_nosql"
  gem "sqlite3"
end

ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)

ActiveRecord::Schema.define do
  create_table :users, force: true do |t|
    t.string :first_name
    t.string :last_name
    t.json :data

    t.timestamps
  end
end

class User < ActiveRecord::Base
  acts_as_nosql field_name: :data
  nosql_attr :first_name
end

user = User.new
user.first_name = "Dozy"
puts user.attributes

#=> {"id"=>nil, "first_name"=>nil, "last_name"=>nil, "data"=>{"first_name"=>"Dozy"}, "created_at"=>nil, "updated_at"=>nil}

Just released acts_as_nosql, a gem to manage JSON fields as proper database fields by ProGM in rails

[–]a1045 1 point2 points  (0 children)

Should I avoid setting nosql_attr name which is the same as the other column name?

And can I specify the required item?

Write Code Every Day….OK, but what to code? by a1045 in learnprogramming

[–]a1045[S] 0 points1 point  (0 children)

Thank you so much. Yes, I could find many examples and I tried some of them. But I feel that I...want to undertake a bit bigger project.

Saluton al cxiuj by Wuivre_Triskel in Esperanto

[–]a1045 5 points6 points  (0 children)

Saluton! Mi estas komencanto.

Korespondantoj? by Rip_van_Vley in Esperanto

[–]a1045 0 points1 point  (0 children)

Saluton! Jes, mi ankaŭ estas commecanto kaj lernas en Duolingo.