Merge lp://staging/~sinzui/launchpad/oil-and-pigment into lp://staging/launchpad

Proposed by Curtis Hovey
Status: Merged
Merged at revision: not available
Proposed branch: lp://staging/~sinzui/launchpad/oil-and-pigment
Merge into: lp://staging/launchpad
Diff against target: 505 lines (+174/-64)
11 files modified
lib/lp/app/stories/launchpad-root/site-search.txt (+1/-2)
lib/lp/app/templates/base-layout-macros.pt (+2/-4)
lib/lp/app/templates/launchpad-search.pt (+7/-2)
lib/lp/blueprints/templates/person-specworkload.pt (+1/-1)
lib/lp/registry/doc/person-karma.txt (+0/-8)
lib/lp/registry/model/mailinglist.py (+3/-1)
lib/lp/registry/model/person.py (+12/-5)
lib/lp/registry/stories/team/xx-team-home.txt (+1/-1)
lib/lp/registry/stories/teammembership/xx-private-membership.txt (+1/-1)
lib/lp/registry/templates/team-portlet-membership.pt (+24/-18)
lib/lp/registry/tests/test_person.py (+122/-21)
To merge this branch: bzr merge lp://staging/~sinzui/launchpad/oil-and-pigment
Reviewer Review Type Date Requested Status
Abel Deuring (community) code Approve
Review via email: mp+23952@code.staging.launchpad.net

Description of the change

This is my branch to fix from trivial issues while my brain is stuck in
first gear.

    lp:~sinzui/launchpad/oil-and-pigment
    Diff size: 489
    Launchpad bug: https://bugs.launchpad.net/bugs/436299
                   https://bugs.launchpad.net/bugs/568336
                   https://bugs.launchpad.net/bugs/130285
                   https://bugs.launchpad.net/bugs/557544
    Test command: ./bin/test -vv lp.registry.tests.test_person
        ./bin/test -t site-search -t xx-team-home -t xx-private-membership \
            -t person-karma
    Pre-implementation: no one
    Target release: 10.04

Fix from trivial issues while my brain is stuck in first gear
--------------------------------------------------------------------

Bug #436299 [Search results give wrong "Registered by" information]
    The maintainer is listed as the registrant. This is wrong. The
    problem is that distributions do not have a registrant.

Bug #568336 [Typo on profile workload page]
    There is a double 'or'

Bug #130285 [Disregard deleted projects from Most active in]
    Deactivated projects are listed in "Most active in" in the profile page
    and the links are a 404.

Bug #557544 [Bad plural on team page ("1 active members")]
    What: "1 active members" can appear on team page. This is incorrect use
    of a plural.

Rules
-----

Bug #436299 [Search results give wrong "Registered by" information]
    Verify there is a registrant using tales before appending the clause.
    tal:define="registrant view/pillar/registrant|nothing"
    tal:condition="registrant"

Bug #568336 [Typo on profile workload page]
    Remove the second 'or'.

Bug #130285 [Disregard deleted projects from lists]
    This issue in on the cusp of *not* trivial because a good understanding
    of pillar name behaviour and karma testing is needed. The fix can be
    easily placed into an existing doc test, but that is not the correct
    location.
    * pillar names (used by karma cache) have no concept of active/inactive.
      The method must filter deactivate pillars /after/ the query to get the
      names. The callsite must request more than is needed because of the
      filtering.
    * Generate the karma for a unit test of the method *and* the private
      methods that were never directly tested.
    * Test that deactivated pillars are not included.
    * ADDENDUM: While I knew how to generate the karma, the reason why
      the karma looks like it is inserted twice was not obvious from existing
      tests. I took an extra hour learning this and adding comments for
      future developers.

Bug #557544 [Bad plural on team page ("1 active members")]
    * Use the plural-message macro to switch between member and members

QA
--

Bug #436299 [Search results give wrong "Registered by" information]
    * Visit https://edge.launchpad.net/+search?field.text=wesnoth
    * Verify that Karianne Fog Heen is listed as the registrant
    * Visit https://edge.launchpad.net/+search?field.text=ubuntu
    * Verify that no registrant is listed:
      Registered on <date>

Bug #568336 [Typo on profile workload page]
    * Visit https://blueprints.edge.launchpad.net/~humphreybc/+specworkload
    * Verify text:
      Benjamin Humphrey is expected to work on, or is its creator

Bug #130285 [Disregard deleted projects from lists]
    * Visit https://edge.launchpad.net/~simon-zoellner
    * Verify that PHProute is not in "Most active in"

Bug #557544 [Bad plural on team page ("1 active members")]
    * Visit https://launchpad.net/~halfgeek.org-ixan
    * Verify the page says 1 active member

Lint
----

Linting changed files:
  lib/lp/app/stories/launchpad-root/site-search.txt
  lib/lp/app/templates/base-layout-macros.pt
  lib/lp/app/templates/launchpad-search.pt
  lib/lp/blueprints/templates/person-specworkload.pt
  lib/lp/registry/doc/person-karma.txt
  lib/lp/registry/model/person.py
  lib/lp/registry/stories/team/xx-team-home.txt
  lib/lp/registry/stories/teammembership/xx-private-membership.txt
  lib/lp/registry/templates/team-portlet-membership.pt
  lib/lp/registry/tests/test_person.py

Test
----

    * lib/lp/app/stories/launchpad-root/site-search.txt
      * Verified that distributions do not get a "registered by" line.
    * lib/lp/registry/doc/person-karma.txt
      * Moved test from doctest to unittest.
    * lib/lp/registry/stories/team/xx-team-home.txt
      * Verified singural and plural cases.
    * lib/lp/registry/stories/teammembership/xx-private-membership.txt
      * Verified singural and plural cases.
    * lib/lp/registry/tests/test_person.py
      * Lint hated this file. I removed a lot of unused imports and vars.
      * I switched the tests to run on the faster DatabaseFunctionalLayer.
      * Added a test for Person.getProjectsAndCategoriesContributedTo()
        and its private helpers. This also tests the new rule to not include
        deactivate projects.

Implementation
--------------

    * lib/lp/app/templates/base-layout-macros.pt
      * Discovered that the macro generated white-space that is inappropirate
        for anchors and punctuation.
    * lib/lp/app/templates/launchpad-search.pt
      * Updated the template to use registrant, not owner, and only print
        the "registered by" line if the pillar has a registrant.
    * lib/lp/blueprints/templates/person-specworkload.pt
      * Removed redundant "or".
    * lib/lp/registry/model/person.py
      * Request 5 extra pillar names and built a list of 5 active pillars.
    * lib/lp/registry/templates/team-portlet-membership.pt
      * Fixed plural rule for active, proposed, and pending membership.
        Sorry that this makes the template hard to read.

To post a comment you must log in.
Revision history for this message
Abel Deuring (adeuring) wrote :
Download full text (3.9 KiB)

Hi Curtis,

overall, a nice branch. I have though a few qestions regarding the
filtering of inactive projects for the karma display, so I'm marking
the MP as "needs information".

> === modified file 'lib/lp/registry/model/person.py'
> --- lib/lp/registry/model/person.py 2010-04-19 21:16:12 +0000
> +++ lib/lp/registry/model/person.py 2010-04-22 18:05:27 +0000
> @@ -850,12 +850,16 @@
> def getProjectsAndCategoriesContributedTo(self, limit=5):
> """See `IPerson`."""
> contributions = []
> - results = self._getProjectsWithTheMostKarma(limit=limit)
> - for pillar_name, karma in results:
> + # Pillars names have no concept of active. Extra pillars names are
> + # requested because deactivated pillars will be filtered out.
> + extra_limit = limit + 5
> + results = self._getProjectsWithTheMostKarma(limit=extra_limit)
> + for pillar_name, karma in results[:limit]:

While you retrieve 5 extra items calling _getProjectsWithTheMostKarma(),
you remove these extra items here ;)

> pillar = getUtility(IPillarNameSet).getByName(pillar_name)
> - contributions.append(
> - {'project': pillar,
> - 'categories': self._getContributedCategories(pillar)})
> + if pillar.active:
> + contributions.append(
> + {'project': pillar,
> + 'categories': self._getContributedCategories(pillar)})
> return contributions

I think that should be

          return contributions[:limit]

combined with a loop over the full result set.

But: Did you consider to change the SQL query in the method
_getProjectsWithTheMostKarma() itself so that only activ projects
are returned (if necessary, using an optional method parameter
"active_only=False")?

While adding five extra items to the result set looks reasonable,
there is the (admittedly largely theoretical) situation that
the result set contains more than five inactive projects, so that
the length of the "effective" list is shorter than expected.

And I would prefer it anyway to do the filtering in
_getProjectsWithTheMostKarma(), even if it would be too cumbersome
to implement in SQL.

[...]

> === modified file 'lib/lp/registry/tests/test_person.py'
> --- lib/lp/registry/tests/test_person.py 2010-02-11 19:26:26 +0000
> +++ lib/lp/registry/tests/test_person.py 2010-04-22 18:05:27 +0000

[...]

> @@ -597,5 +601,103 @@
> assignee=self.user)
>
>
> +class TestPersonKarma(TestCaseWithFactory):
> +
> + layer = DatabaseFunctionalLayer
> +
> + def setUp(self):
> + super(TestPersonKarma, self).setUp()
> + self.person = self.factory.makePerson()
> + a_product = self.factory.makeProduct(name='aa')
> + b_product = self.factory.makeProduct(name='bb')
> + self.c_product = self.factory.makeProduct(name='cc')
> + self.cache_manager = getUtility(IKarmaCacheManager)
> + self._makeKarmaCache(
> + self.person, a_product, [('bugs', 10)])
> + self._makeKarmaCache(
> + self.person, b_product, [('answers', 50)])
> + self._makeKarmaCache(
> + self....

Read more...

review: Needs Information (code)
Revision history for this message
Curtis Hovey (sinzui) wrote :
Download full text (6.1 KiB)

On Fri, 2010-04-23 at 13:41 +0000, Abel Deuring wrote:
> Review: Needs Information code
> Hi Curtis,
>
> overall, a nice branch. I have though a few qestions regarding the
> filtering of inactive projects for the karma display, so I'm marking
> the MP as "needs information".
>
> > === modified file 'lib/lp/registry/model/person.py'
> > --- lib/lp/registry/model/person.py 2010-04-19 21:16:12 +0000
> > +++ lib/lp/registry/model/person.py 2010-04-22 18:05:27 +0000
> > @@ -850,12 +850,16 @@
> > def getProjectsAndCategoriesContributedTo(self, limit=5):
> > """See `IPerson`."""
> > contributions = []
> > - results = self._getProjectsWithTheMostKarma(limit=limit)
> > - for pillar_name, karma in results:
> > + # Pillars names have no concept of active. Extra pillars names are
> > + # requested because deactivated pillars will be filtered out.
> > + extra_limit = limit + 5
> > + results = self._getProjectsWithTheMostKarma(limit=extra_limit)
> > + for pillar_name, karma in results[:limit]:
>
> While you retrieve 5 extra items calling _getProjectsWithTheMostKarma(),
> you remove these extra items here ;)

I am incompetent. I removed the limit on the iterator. I added a guard
in the loop to break at the limit.

> > pillar = getUtility(IPillarNameSet).getByName(pillar_name)
> > - contributions.append(
> > - {'project': pillar,
> > - 'categories': self._getContributedCategories(pillar)})
> > + if pillar.active:
> > + contributions.append(
> > + {'project': pillar,
> > + 'categories': self._getContributedCategories(pillar)})
> > return contributions
>
> I think that should be
>
> return contributions[:limit]
>
> combined with a loop over the full result set.

I prefer a guard in the loop. The loop may make 5 extra SQL queries for
data that will not be used. _getContributedCategories() is a call to the
db.

> But: Did you consider to change the SQL query in the method
> _getProjectsWithTheMostKarma() itself so that only activ projects
> are returned (if necessary, using an optional method parameter
> "active_only=False")?

Yes, the query would insane because it is often nothing to join on. We
are querying pillar names, not objects. that is why our code always
filters *after* the pillar_name is used to get the pillar (product,
distribution, project group)

> While adding five extra items to the result set looks reasonable,
> there is the (admittedly largely theoretical) situation that
> the result set contains more than five inactive projects, so that
> the length of the "effective" list is shorter than expected.

Yes. This hack is the same approach taken when getting a short list of
bugs that may have private ones filtered out. The complaints from users
is about 1 deactivated project in the list. We are providing coverage
for 5 deactivated projects.

> And I would prefer it anyway to do the filtering in
> _getProjectsWithTheMostKarma(), even if it would be too cumbersome
> to implement in SQL.

I do not think that is practical. As I said above, ...

Read more...

Revision history for this message
Abel Deuring (adeuring) wrote :

OK, looks good now. (Though I would still prefer to move the filtering to _getprojectsWithMostKarma(), even if it is implemented in Python)

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.