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"
updated_at = Cache.get(key)
return updated_at if updated_at
# if we do not have it cached, do lookup
if !updated_at
o = select(:updated_at).order(updated_at: :desc, id: :desc).limit(1).first
if o
updated_at = o.updated_at
latest_change_set(updated_at)
end
end
updated_at = order(updated_at: :desc, id: :desc).limit(1).pluck(:updated_at).first
return if !updated_at
latest_change_set(updated_at)
updated_at
end