forked from OpenNeo/impress
stop -type:x queries from lagging out due to group by optimization blah
This commit is contained in:
parent
8b159c02bd
commit
a196c43253
1 changed files with 4 additions and 2 deletions
|
@ -359,7 +359,7 @@ class Item < ActiveRecord::Base
|
||||||
# SWFs that don't match end up being NULL rows. Then we take the max SWF
|
# SWFs that don't match end up being NULL rows. Then we take the max SWF
|
||||||
# asset ID, which is NULL if and only if there are no rows that matched
|
# asset ID, which is NULL if and only if there are no rows that matched
|
||||||
# the zone requirement. If that max was NULL, return the object.
|
# the zone requirement. If that max was NULL, return the object.
|
||||||
scope.joins(
|
item_ids = select(arel_table[:id]).joins(
|
||||||
"LEFT JOIN #{ParentSwfAssetRelationship.table_name} #{psa.name} ON " +
|
"LEFT JOIN #{ParentSwfAssetRelationship.table_name} #{psa.name} ON " +
|
||||||
psa[:swf_asset_type].eq(SwfAssetType)
|
psa[:swf_asset_type].eq(SwfAssetType)
|
||||||
.and(psa[:parent_id].eq(arel_table[:id]))
|
.and(psa[:parent_id].eq(arel_table[:id]))
|
||||||
|
@ -373,7 +373,9 @@ class Item < ActiveRecord::Base
|
||||||
.to_sql
|
.to_sql
|
||||||
).
|
).
|
||||||
group("#{table_name}.id").
|
group("#{table_name}.id").
|
||||||
having("MAX(#{sa.name}.id) IS NULL") # SwfAsset.arel_table[:id].maximum has no #eq
|
having("MAX(#{sa.name}.id) IS NULL"). # SwfAsset.arel_table[:id].maximum has no #eq
|
||||||
|
map(&:id)
|
||||||
|
scope.where(arel_table[:id].in(item_ids))
|
||||||
}
|
}
|
||||||
|
|
||||||
class Condition < String
|
class Condition < String
|
||||||
|
|
Loading…
Reference in a new issue