This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Yam | |
class ActionControllerLogger < YamLogger | |
def self.subscribe | |
ActiveSupport::Notifications.subscribe "process_action.action_controller" do |*args| | |
event = ActiveSupport::Notifications::Event.new *args | |
self.structure(event.payload,event.duration, event.name) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"feeds":[ | |
{ | |
"restriction_level":"public", | |
"photos":[ | |
{ | |
"post_id":1, | |
"photo":{ | |
"web_m_retina":"/uploads/post_photo/photo/bc003114/76eaa3f5/6e4d375e/a1efd84e/web_m_retina_1505067265-1d27fa79.jpg", | |
"web_m":"/uploads/post_photo/photo/bc003114/76eaa3f5/6e4d375e/a1efd84e/web_m_1505067265-1d27fa79.jpg", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
data = (0..50_000_000) | |
Benchmark.bm do |x| | |
x.report(:find) { data.find {|number| number > 40_000_000 } } | |
x.report(:bsearch) { data.bsearch {|number| number > 40_000_000 } } | |
end | |
user system total real |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
data = (0..50_000_000) | |
Benchmark.bm do |x| | |
x.report(:find) { data.find {|number| number > 40_000_000 } } | |
x.report(:bsearch) { data.bsearch {|number| number > 40_000_000 } } | |
end | |
user system total real |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def list_user_posts(user_id) do | |
Post | |
|> where([p], p.user_id == ^user_id) | |
|> preload([:post_photos, user: [:country, :city]]) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def list_user_posts(user_id) do | |
Post | |
|> distinct(true) | |
|> where([p], p.user_id == ^user_id) | |
|> join(:left, [p], d in assoc(p, :user)) | |
|> join(:left, [_p, d], co in assoc(d, :country)) | |
|> join(:left, [_p, d], ci in assoc(d, :city)) | |
|> join(:left, [p, _d], ph in assoc(p, :post_photos)) | |
|> preload([_p, d, co, ci, ph], user: {d, country: co, city: ci}, post_photos: ph) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Benchee.run(%{ | |
"Preload 1 query sync" => fn -> one_query |> Repo.all(in_parallel: false) end, | |
"Preload 1 query async" => fn -> one_query |> Repo.all(in_parallel: true) end, | |
"Preload 5 query async" => fn -> five_query |> Repo.all(in_parallel: true) end, | |
"Preload 5 query sync" => fn -> five_query |> Repo.all(in_parallel: false) end | |
}, time: 10, memory_time: 2, warmup: 5) | |
Name ips average deviation median 99th % | |
Preload 5 query async 191.25 5.23 ms ±25.81% 4.96 ms 10.02 ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def list_user_posts(user_id) do | |
Post | |
|> where([p], p.user_id == ^user_id) | |
|> join( | |
:inner, | |
[post], | |
user in User, | |
on: user.id == post.user_id and is_nil(user.deleted_at) == true and | |
is_nil(user.blocked_at) == true | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def list_user_posts(user_id) do | |
Post | |
|> where([p], p.user_id == ^user_id) | |
|> preload(post_photos: ^from(p in PostPhoto, order_by: p.position)) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def list_user_posts_select(user_id) do | |
Post | |
|> where([p], p.user_id == ^user_id) | |
|> join( | |
:inner, | |
[post], | |
user in User, | |
on: user.id == post.user_id and is_nil(user.deleted_at) == true and | |
is_nil(user.blocked_at) == true | |
) |
OlderNewer