I had trouble reading this, so I refactored it to use more descriptive
names. If you like what I've done then I think it would be a good
change to make:
Just because everything else seems to not be camel-case any more,
consider doing s/clauseTables/clause_tables/g.
[4]
+ origin = [BugTask]
+ already_joined = set(origin)
+ for table, join in join_tables:
+ origin.append(join)
+ already_joined.add(table)
+ for table, join in prejoin_tables:
+ if table not in already_joined:
+ origin.append(join)
+ already_joined.add(table)
+ for table in clauseTables:
+ if table not in already_joined:
+ origin.append(table)
+ return origin
Does the order matter? If not, this could be:
table_joins = chain(join_tables, prejoin_tables)
return set(table for (table, join) in table_joins).union(clauseTables)
Perhaps it's worth documenting that resultrow must be BugTask, a
column of BugTask, or a sequence containing either of the above?
Assuming that's correct.
[7]
+ decorator=lambda row: bugtask_decorator(row[0])
s/=/ = /
Ah, this means that the rule in [6] should be modified to be:
resultrow must be BugTask, a column of BugTask, or a sequence whose
first element is either of the above.
It might be worth adding an assert to that.
[8]
+ undecorated = kw.get('undecorated', False)
...
+ if prejoins:
+ decorator=lambda row: bugtask_decorator(row[0])
+ else: decorator = bugtask_decorator
...
+ if undecorated:
+ return resultset
return DecoratedResultSet(resultset, result_decorator=decorator)
...
+ if undecorated:
+ return result
return DecoratedResultSet(result, result_decorator=decorator)
I think the undecorated argument is a slightly ugly wart. Instead,
consider always returning the DecoratedResultSet, and change
searchBugIds() to:
Cool :) Lots of comments, but none of them are very important.
[1]
+ Or(BugTask. sourcepackagena meID == ription. sourcepackagena meID, ription. sourcepackagena me == None)))
+ StructuralSubsc
+ StructuralSubsc
Indentation is a little confusing there.
[2]
+ join_clause = ( ription. productID) productseriesID == ription. productseriesID )) model.product import Product projectID == StructuralSubsc ription. projectID, distributionID == ription. distributionID) , sourcepackagena meID == ription. sourcepackagena meID, ription. sourcepackagena me == None))) distroseriesID == ription. distroseriesID) ) ription. milestoneID)
+ BugTask.productID == StructuralSubsc
+ join_clause = Or(
+ join_clause,
+ (BugTask.
+ StructuralSubsc
+ # Circular.
+ from lp.registry.
+ join_clause = Or(
+ join_clause,
+ And(Product.
+ BugTask.product == Product.id))
+ join_clause = Or(
+ join_clause,
+ And((BugTask.
+ StructuralSubsc
+ Or(BugTask.
+ StructuralSubsc
+ StructuralSubsc
+ join_clause = Or(
+ join_clause,
+ (BugTask.
+ StructuralSubsc
+ join_clause = Or(
+ join_clause,
+ BugTask.milestoneID == StructuralSubsc
I had trouble reading this, so I refactored it to use more descriptive
names. If you like what I've done then I think it would be a good
change to make:
ssub_ match_product = (
BugTask. productID ==
StructuralSubs cription. productID) match_productse ries = (
BugTask. productseriesID ==
StructuralSubs cription. productseriesID ) match_project = And(
Product. projectID ==
StructuralSubs cription. projectID,
BugTask. product == Product.id) match_distribut ion = (
BugTask. distributionID ==
StructuralSubs cription. distributionID) match_sourcepac kagename = (
BugTask. sourcepackagena meID ==
StructuralSubs cription. sourcepackagena meID) match_null_ sourcepackagena me = (
StructuralSubs cription. sourcepackagena me == None) match_distribut ion_with_ optional_ package = And(
ssub_match_ distribution, Or(
ssub_ match_sourcepac kagename,
ssub_ match_null_ sourcepackagena me)) match_distribut ion_series = (
BugTask. distroseriesID ==
StructuralSubs cription. distroseriesID) match_milestone = (
BugTask. milestoneID ==
StructuralSubs cription. milestoneID)
ssub_
ssub_
ssub_
ssub_
ssub_
ssub_
ssub_
ssub_
join_clause = Or(
ssub_match_ product,
ssub_match_ productseries,
ssub_match_ project,
ssub_match_ distribution_ with_optional_ package,
ssub_match_ distribution_ series,
ssub_match_ milestone)
[3]
+ query, clauseTables, orderby_arg, decorator, join_tables,
Just because everything else seems to not be camel-case any more, clause_ tables/ g.
consider doing s/clauseTables/
[4]
+ origin = [BugTask] joined. add(table) joined. add(table) append( table)
+ already_joined = set(origin)
+ for table, join in join_tables:
+ origin.append(join)
+ already_
+ for table, join in prejoin_tables:
+ if table not in already_joined:
+ origin.append(join)
+ already_
+ for table in clauseTables:
+ if table not in already_joined:
+ origin.
+ return origin
Does the order matter? If not, this could be:
table_joins = chain(join_tables, prejoin_tables) .union( clauseTables)
return set(table for (table, join) in table_joins)
[5]
+ (query, clauseTables, orderby, bugtask_decorator, join_tables, results) = self.buildQuery (params)
+ has_duplicate_
I /think/ we're meant to use [] for unwrapping.
[6]
+ resultset = store.using( *outer_ origin) .find(
+ resultrow, In(BugTask.id, subquery))
Perhaps it's worth documenting that resultrow must be BugTask, a
column of BugTask, or a sequence containing either of the above?
Assuming that's correct.
[7]
+ decorator=lambda row: bugtask_ decorator( row[0])
s/=/ = /
Ah, this means that the rule in [6] should be modified to be:
resultrow must be BugTask, a column of BugTask, or a sequence whose
first element is either of the above.
It might be worth adding an assert to that.
[8]
+ undecorated = kw.get( 'undecorated' , False) decorator( row[0])
decorator = bugtask_decorator Set(resultset, result_ decorator= decorator) Set(result, result_ decorator= decorator)
...
+ if prejoins:
+ decorator=lambda row: bugtask_
+ else:
...
+ if undecorated:
+ return resultset
return DecoratedResult
...
+ if undecorated:
+ return result
return DecoratedResult
I think the undecorated argument is a slightly ugly wart. Instead,
consider always returning the DecoratedResultSet, and change
searchBugIds() to:
return self._search( BugTask. bugID, [], params).result_set
[9]
+ # We need to process subscriptions, so pull all the
+ # subscribes into the cache, then update recipients
+ # with the subscriptions.
s/subscribes/ subscribers/
[10]
+class ProjectGroupAnd DistributionTes ts:
+ """Tests which are useful for project groups and distributions."""
These are about verifying distinct results. Consider renaming and
changing the docstring to reflect that.
[11]
+ BugTaskSearchParams instancs, while BugTaskSet. searchBugIds( )
s/instancs/ instances/