launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #08372
[Merge] lp:~lifeless/launchpad/generate-htaccess-speed into lp:launchpad
Robert Collins has proposed merging lp:~lifeless/launchpad/generate-htaccess-speed into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~lifeless/launchpad/generate-htaccess-speed/+merge/108074
Eliminate late-evaluation in htaccess file creation. No tests (they are coming via work jml is doing), existing tests pass, so the contract is maintained, and we have manually observed a 5-fold improvement on 5000 subscriber ppas.
--
https://code.launchpad.net/~lifeless/launchpad/generate-htaccess-speed/+merge/108074
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~lifeless/launchpad/generate-htaccess-speed into lp:launchpad.
=== modified file 'database/schema/security.cfg'
--- database/schema/security.cfg 2012-05-25 18:08:42 +0000
+++ database/schema/security.cfg 2012-05-30 22:51:22 +0000
@@ -2219,6 +2219,7 @@
[generateppahtaccess]
groups=script
+public.account = SELECT
public.archive = SELECT
public.archiveauthtoken = SELECT, UPDATE
public.archivesubscriber = SELECT, UPDATE
=== modified file 'lib/lp/archivepublisher/htaccess.py'
--- lib/lp/archivepublisher/htaccess.py 2012-05-30 16:32:50 +0000
+++ lib/lp/archivepublisher/htaccess.py 2012-05-30 22:51:22 +0000
@@ -22,6 +22,7 @@
from zope.component import getUtility
+from lp.registry.interfaces.person import IPersonSet
from lp.soyuz.interfaces.archiveauthtoken import IArchiveAuthTokenSet
from lp.soyuz.model.archiveauthtoken import ArchiveAuthToken
@@ -80,14 +81,20 @@
assert archive.private, "Archive %r must be private" % archive
if tokens is None:
- tokens = getUtility(IArchiveAuthTokenSet).getByArchive(
- archive).order_by(ArchiveAuthToken.id)
+ tokens = getUtility(IArchiveAuthTokenSet).getByArchive(archive)
+ tokens = list(tokens)
# The first .htpasswd entry is the buildd_secret.
yield (BUILDD_USER_NAME, archive.buildd_secret, BUILDD_USER_NAME[:2])
+ person_ids = map(attrgetter('person_id'), tokens)
+ valid_persons = dict((person.id, person) for person in
+ getUtility(IPersonSet).getPrecachedPersonsFromIDs(
+ person_ids, need_validity=True) if person.is_valid_person)
+ usable_tokens = [(token, valid_persons[token.person_id])
+ for token in tokens if token.person_id in valid_persons]
# Iterate over tokens and write the appropriate htpasswd
- # entries for them. For consistent sort order, the tokens
- # should be ordered by id.
- for token in tokens:
- yield (token.person.name, token.token, token.person.name[:2])
+ # entries for them. Use a consistent sort order so that the
+ # generated file can be compared to an existing one later.
+ for token, person in sorted(usable_tokens, key=lambda item:item[0].id):
+ yield (person.name, token.token, person.name[:2])
=== modified file 'lib/lp/soyuz/interfaces/archiveauthtoken.py'
--- lib/lp/soyuz/interfaces/archiveauthtoken.py 2011-12-24 16:54:44 +0000
+++ lib/lp/soyuz/interfaces/archiveauthtoken.py 2012-05-30 22:51:22 +0000
@@ -13,7 +13,10 @@
]
from lazr.restful.fields import Reference
-from zope.interface import Interface
+from zope.interface import (
+ Attribute,
+ Interface,
+ )
from zope.schema import (
Datetime,
Int,
@@ -36,6 +39,7 @@
person = Reference(
IPerson, title=_("Person"), required=True, readonly=True,
description=_("The person for this authorisation token."))
+ person_id = Attribute('db person value')
date_created = Datetime(
title=_("Date Created"), required=True, readonly=True,
Follow ups