Refactored code layout and prefer pluck over select to avoid unnecessary memory allocation.

This commit is contained in:
Thorsten Eckel 2018-06-16 12:14:49 +02:00
parent c3105bb804
commit 789f2b4807

View file

@ -21,14 +21,13 @@ returns
key = "#{new.class.name}_latest_change" key = "#{new.class.name}_latest_change"
updated_at = Cache.get(key) updated_at = Cache.get(key)
return updated_at if updated_at
# if we do not have it cached, do lookup # if we do not have it cached, do lookup
if !updated_at updated_at = order(updated_at: :desc, id: :desc).limit(1).pluck(:updated_at).first
o = select(:updated_at).order(updated_at: :desc, id: :desc).limit(1).first
if o return if !updated_at
updated_at = o.updated_at latest_change_set(updated_at)
latest_change_set(updated_at)
end
end
updated_at updated_at
end end