What is the difference between pull request and merge request?
自分がされたり、自分がしたり
そのクエリ参照する変数宣言、一定の時しか必要ないよね?
defcreate_current_banner_info(user, now = Time.now)
user_items = user.items.pluck(:item_code, :quantity).to_h
BannerMaster.holdings(now).each_with_object([]) do |banner, res|
if banner.user_condition_need?
case banner.condition_type
when :fulfill_item
nextunless user_items[banner.neccesary_item_code].to_i >= banner.nessesary_quantity
when ...
...
endend
res << banner.as_json(:code, :banner_type, :banner_icon, ...)
end
アイテムを保持しているかで表示するかを分けるバナーって複数あったりもするだろうけど、いつもある訳じゃないよね? だったら一番上のuser_itemsはnilで宣言しちゃって、 when :fulfill_item の中に入ったところで||=で宣言すれば無駄ないと思うよ。 いやそれよりも、もっと良い方法あるな。 そもそもさ、複数あるって言っても、pluckして必要なデータの取得を最低限にしてると言ってもさ、全部のアイテム参照してるのかなり無駄じゃん。 バナーを表示するかとレスポンス作っているところを一緒くたにしないでさ、先にアイテムが必要なバナーだけを抽出してしまえば、その参照すべきアイテムコード群を取れるよね。そうすれば本当に必要最低限しか取らずに済むよ。 で、今すぐマージ必要? 必要じゃないか、分かった。じゃあお願いします。
array = (1..1000).to_a
begin
now = Time.now
1000.times do |n|
array.include?(n + 1)
end
p Time.now - now
end
=> 0.0051824
2.
hash = (1..1000).each_with_object({}){|n, res| res[n] = true}
begin
now = Time.now
1000.times do |n|
!!hash[n + 1]
end
p Time.now - now
end
=> 0.0001501
worker | LOADING Redis is loading the dataset in memory
worker | /app/vendor/bundle/ruby/2.5.0/gems/redis-4.0.3/lib/redis/client.rb:124:in `call'
worker | /app/vendor/bundle/ruby/2.5.0/gems/redis-4.0.3/lib/redis/client.rb:107:in `block in connect'
(略)
worker | /app/vendor/bundle/ruby/2.5.0/gems/redis-4.0.3/lib/redis.rb:278:in `info'
worker | /app/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.2.3/lib/sidekiq.rb:113:in `block in redis_info'
worker | /app/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.2.3/lib/sidekiq.rb:95:in `block in redis'
原因
redisコンテナ起動時に --appendonly yes が指定されていた。
LOADING Redis is loading the dataset in memory というエラーは、 AOF(Append-only File)からデータをメモリ上に展開している間に更新(SET)などのコマンドを実行しようとした際に発生するらしい。
RDB/AOFファイルをローディングしている間、SETコマンドのようなものを実行すれば “(error)LOADING Redis is loading the dataset in memory”このようなエラーを出すが、infoコマンドは実行されます。 したがって、infoコマンドでローディング中なのか確認することができます。 REDIS INFO [section] コマンド
503 (HTML形式で) ‘ERROR: The request could not be satisfied’
レスポンス
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>502 ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
CloudFront attempted to establish a connection with the origin, but either the attempt failed or the origin closed the connection.
We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
<BR clear="all">
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>
原因
オリジン(API Gateway)に対して http でアクセスしている
CloudFront のオリジンの設定(Origin Protocol Policy)が HTTP Only のようになっていないか確認する
API Gateway は HTTPS しかサポートしていないので、 HTTPS Only とするべき