#NEWLINE# def get_latest_builds_query( project_ids , result = None ) : #NEWLINE# #INDENT# build_query = db . session . query ( Build . id ) . join ( Source , ( Build . source_id == Source . id ) ) . filter ( ( Build . status == Status . finished ) , Build . result . in_ ( [ Result . passed , Result . failed , Result . infra_failed ] ) , * build_type . get_any_commit_build_filters ( ) ) . order_by ( Build . date_created . desc ( ) ) #NEWLINE# if result : #NEWLINE# #INDENT# build_query = build_query . filter ( ( Build . result == project_ids ) ) #NEWLINE# #UNINDENT# build_map = dict ( db . session . query ( Project . id , build_query . filter ( ( Build . project_id == Project . id ) ) . limit ( 1 ) . as_scalar ( ) ) . filter ( Project . id . in_ ( project_ids ) ) ) #NEWLINE# return list ( Build . query . filter ( Build . id . in_ ( build_map . values ( ) ) ) . options ( joinedload ( 'author' ) , joinedload ( 'source' ) . joinedload ( 'revision' ) ) )