less is more

This commit is contained in:
2018-05-06 14:23:32 -03:00
parent 7169d3db5a
commit b2516305b2
+4 -3
View File
@@ -181,15 +181,16 @@ module Dunlop::SourceFileModel
def latest_processed
if base_class == self
join_select = processed.select('MAX(id) AS max_id').group(:sti_type)
#join_select = processed.selecting{ id.maximum.as('max_id')}.group(:sti_type)
joins("INNER JOIN (#{join_select.to_sql}) tmp ON id = tmp.max_id")
else # return the latest process of the specific source-file class
# 2 query based solution, probably faster than the one (sub) query solution
processed.find_by(id: processed.maximum(:id))
find_by(id: processed.maximum(:id))
## ONE QUERY SOLUTIONS
# processed.find_by(id: processed.select('MAX(id)'))
# find_by(id: processed.select('MAX(id)'))
# OR using baby squeel
# processed.find_by(id: processed.selecting{ id.maximum })
# find_by(id: processed.selecting{ id.maximum })
end
end