mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-03 10:48:03 +08:00
Modify ModuleBuild._add_virtual_streams_filter to use a subquery to better support Postgres
The old way performed a `DISTINCT (module_builds.id)` on the original query passed in to ModuleBuild._add_virtual_streams_filter, but this caused issues when the original query was ordered by something other than ID on Postgres databases. This new approach uses a subquery to filter that module builds with the desired virtual streams, and then joins this subquery to the original query.
This commit is contained in:
@@ -419,11 +419,21 @@ class ModuleBuild(MBSBase):
|
||||
if not virtual_streams:
|
||||
return query
|
||||
|
||||
return (
|
||||
query.join(VirtualStream, ModuleBuild.virtual_streams)
|
||||
# Create a subquery that filters down all the module builds that contain the virtual
|
||||
# streams. Using distinct is necessary since a module build may contain multiple virtual
|
||||
# streams that are desired.
|
||||
modules_with_virtual_streams = (
|
||||
session.query(ModuleBuild)
|
||||
.join(VirtualStream, ModuleBuild.virtual_streams)
|
||||
.filter(VirtualStream.name.in_(virtual_streams))
|
||||
.order_by(ModuleBuild.id)
|
||||
.distinct(ModuleBuild.id)
|
||||
)
|
||||
).subquery()
|
||||
|
||||
# Join the original query with the subquery so that only module builds with the desired
|
||||
# virtual streams remain
|
||||
return query.join(
|
||||
modules_with_virtual_streams, ModuleBuild.id == modules_with_virtual_streams.c.id)
|
||||
|
||||
@staticmethod
|
||||
def get_last_builds_in_stream_version_lte(session, name, stream_version, virtual_streams=None):
|
||||
|
||||
Reference in New Issue
Block a user