Merge lp:~allenap/launchpad/subscribe-to-tag-bug-151129-2 into lp:launchpad
| Status: | Merged | ||||
|---|---|---|---|---|---|
| Approved by: | Gavin Panella on 2010-11-19 | ||||
| Approved revision: | no longer in the source branch. | ||||
| Merged at revision: | 11972 | ||||
| Proposed branch: | lp:~allenap/launchpad/subscribe-to-tag-bug-151129-2 | ||||
| Merge into: | lp:launchpad | ||||
| Prerequisite: | lp:~allenap/launchpad/subscribe-to-tag-bug-151129 | ||||
| Diff against target: |
432 lines (+284/-92) 2 files modified
lib/lp/registry/model/structuralsubscription.py (+250/-89) lib/lp/registry/tests/test_structuralsubscriptiontarget.py (+34/-3) |
||||
| To merge this branch: | bzr merge lp:~allenap/launchpad/subscribe-to-tag-bug-151129-2 | ||||
| Related bugs: |
|
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| j.c.sackett (community) | code* | 2010-11-18 | Approve on 2010-11-19 |
| Abel Deuring (community) | code | Approve on 2010-11-19 | |
|
Review via email:
|
|||
Commit Message
[r=adeuring,
Description of the Change
This changes the way subscription filters are found. Instead of some
left joins and some array gymnastics there is a convenience class,
BugFilterSetBui
match. From that it can figure out which subscriptions match.
| Gavin Panella (allenap) wrote : | # |
Thanks for the excellent review :)
> I am a little weirded out by it living alone in models; the logic is a file in
> models should have a model in it--this one is just utilities for another model
> file. Since it doesn't have use outside of structuralsubsc
> it might be better added to that file. I don't think that hurts the
> readability of that file, since the logic is still nicely contained in the
> class you created.
Yeah, fair point. I moved it out because it helped me concentrate
while working on it, but it was a lot messier then. I've moved it
back.
...
> > + # Set up common filter conditions.
> > + if len(self.tags) == 0:
> > + self.filter_
> > + BugSubscription
> > + self.base_
> > + else:
> > + self.filter_
> > + BugSubscription
> > + self.base_
> > +
>
> A quick comment here explaining the logic of setting up exclude_any vs
> include_any would be good.
Done.
...
> > + def _filters_
> > + # The expressions returned by this function are used in set (union,
> > + # intersect, except) operations at the *filter* level. However, the
> > + # interesting result of these set operations is the structural
> > + # subscription, hence both columns are included in the expressions
> > + # generated. Since a structural subscription can have zero or more
> > + # filters, and a filter can never be associated with more than one
> > + # subscription, the set operations are unaffected.
> > + return Select(
> > + columns=(
> > + # Alias this column so it can be selected in
> > + # subscriptions_
> > + Alias(
> > + BugSubscription
> > + "structural_
> > + BugSubscription
> > + tables=(
> > + StructuralSubsc
> > + where=And(
> > + BugSubscription
> > + StructuralSubsc
> > + self.filter_
> > + where_condition),
> > + **extra)
> > +
>
> I would prefer some sort of docstring for this in place of in addition to the
> comment block at the top.
Done.
...
> > + def _filters_
> > + tags_array = "ARRAY[%s]::TEXT[]" % ",".join(
> > + quote(tag) for tag in self.tags)
> > + return self._filters_
> > + BugSubscription
> > + And(
> > + BugSubscription
> > + BugSubscription
> > + BugSubscription
> > + self.filter_
> > + where_condition),
> > + group_by=(
> > + ...
| Abel Deuring (adeuring) wrote : | # |
A very nice branch and a very nice review!
Just one more nitpick: Gavin, could you add a doc string to BugFilterSetBiu

Gavin--
This is a really nice branch! I like cutting out all of that logic into the utility.
I am a little weirded out by it living alone in models; the logic is a file in models should have a model in it--this one is just utilities for another model file. Since it doesn't have use outside of structuralsubsc ription. py, I think it might be better added to that file. I don't think that hurts the readability of that file, since the logic is still nicely contained in the class you created.
Additional comments are in the diff below.
> === modified file 'lib/lp/ registry/ model/structura lsubscription. py' registry/ model/structura lsubscription. py 2010-11-18 16:11:43 +0000 registry/ model/structura lsubscription. py 2010-11-18 16:11:51 +0000 sForBugTask( self, bugtask, level): scriptionTarget `.""" ription, Filter, Filter. structural_ subscription_ id == ( ription. id)), FilterStatus, FilterStatus. filter_ id == ( Filter. id)), FilterImportanc e, FilterImportanc e.filter_ id == ( Filter. id)), FilterTag " Filter. id AND include") is_empty = SQL( FilterTag " Filter. id AND NOT include") is_empty = SQL( all_combinator( find_all_ expr, find_any_expr): Filter. find_all_ tags " bug.tags) == 0: Filter. include_ any_tags == False, is_empty,
> --- lib/lp/
> +++ lib/lp/
> def getSubscription
> """See `IStructuralSub
> - origin = [
> - StructuralSubsc
> - LeftJoin(
> - BugSubscription
> - BugSubscription
> - StructuralSubsc
> - LeftJoin(
> - BugSubscription
> - BugSubscription
> - BugSubscription
> - LeftJoin(
> - BugSubscription
> - BugSubscription
> - BugSubscription
> - ]
> -
> - # An ARRAY[] expression for the given bug's tags.
> - tags_array = "ARRAY[%s]::TEXT[]" % ",".join(
> - quote(tag) for tag in bugtask.bug.tags)
> -
> - # The tags a subscription requests for inclusion.
> - tags_include_expr = (
> - "SELECT tag FROM BugSubscription
> - "WHERE filter = BugSubscription
> - tags_include_array = "ARRAY(%s)" % tags_include_expr
> - tags_include_
> - "ARRAY[]::TEXT[] = %s" % tags_include_array)
> -
> - # The tags a subscription requests for exclusion.
> - tags_exclude_expr = (
> - "SELECT tag FROM BugSubscription
> - "WHERE filter = BugSubscription
> - tags_exclude_array = "ARRAY(%s)" % tags_exclude_expr
> - tags_exclude_
> - "ARRAY[]::TEXT[] = %s" % tags_exclude_array)
> -
> - # Choose the correct expression depending on the find_all_tags flag.
> - def tags_find_
> - return SQL(
> - "CASE WHEN BugSubscription
> - "THEN (%s) ELSE (%s) END" % (find_all_expr, find_any_expr))
> -
> - if len(bugtask.
> - tag_conditions = [
> - BugSubscription
> - # The subscription's required tags must be an empty set.
> - tags_include_
> - # The subscription's excluded tags can be anything so no
> - # condition...