give personas a Version to simplify queries
This commit is contained in:
Родитель
699d8c11b9
Коммит
96afc63f51
|
@ -372,3 +372,11 @@ def _group_addons(qs):
|
|||
# array.array() lets us calculate similarities much faster.
|
||||
addons[addon] = array.array('l', cs)
|
||||
return addons
|
||||
|
||||
|
||||
@cronjobs.register
|
||||
def give_personas_versions():
|
||||
cursor = connections['default'].cursor()
|
||||
path = os.path.join(settings.ROOT, 'migrations/149-personas-versions.sql')
|
||||
with open(path) as f:
|
||||
cursor.execute(f.read())
|
||||
|
|
|
@ -70,11 +70,22 @@
|
|||
"localized_string": "My Persona"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 15663,
|
||||
"model": "versions.version",
|
||||
"fields": {
|
||||
"created": "2010-01-14 11:39:40",
|
||||
"modified": "2010-01-14 11:40:45",
|
||||
"version": "0",
|
||||
"addon": 15663
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 15663,
|
||||
"model": "addons.addon",
|
||||
"fields": {
|
||||
"slug": "a15663",
|
||||
"_current_version": 15663,
|
||||
"dev_agreement": 0,
|
||||
"eula": null,
|
||||
"last_updated": "2009-03-30 23:17:40",
|
||||
|
|
|
@ -99,7 +99,7 @@ class AddonManager(amo.models.ManagerBase):
|
|||
kw = dict((prefix + k, v) for k, v in kw.items())
|
||||
return Q(*args, **kw)
|
||||
|
||||
return q(q(type=amo.ADDON_PERSONA) | q(_current_version__isnull=False),
|
||||
return q(q(_current_version__isnull=False),
|
||||
disabled_by_user=False, status__in=status)
|
||||
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
"model": "addons.addon",
|
||||
"fields": {
|
||||
"slug": "15679",
|
||||
"_current_version": 15679,
|
||||
"dev_agreement": 0,
|
||||
"last_updated": "2009-03-30 23:18:20",
|
||||
"average_daily_downloads": 0,
|
||||
|
@ -523,6 +524,16 @@
|
|||
"created": "2007-03-05 13:09:27"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 15679,
|
||||
"model": "versions.version",
|
||||
"fields": {
|
||||
"created": "2010-01-14 11:39:40",
|
||||
"modified": "2010-01-14 11:40:45",
|
||||
"version": "0",
|
||||
"addon": 15679
|
||||
}
|
||||
},
|
||||
{
|
||||
"pk": 91189,
|
||||
"model": "versions.version",
|
||||
|
|
|
@ -847,6 +847,10 @@ class TestLegacyRedirects(test_utils.TestCase):
|
|||
class TestFeaturedPage(test_utils.TestCase):
|
||||
fixtures = ('base/apps', 'base/featured', 'addons/featured')
|
||||
|
||||
def setUp(self):
|
||||
if hasattr(Addon, '_feature'):
|
||||
del Addon._feature
|
||||
|
||||
def test_featured_addons(self):
|
||||
"""Make sure that only featured add-ons are shown"""
|
||||
# Persona returned by featured.
|
||||
|
|
|
@ -133,8 +133,7 @@ def themes(request, category=None):
|
|||
raise http.Http404()
|
||||
addons = addons.filter(categories__id=category.id)
|
||||
|
||||
count = addons.with_index(addons='type_status_inactive_idx').count()
|
||||
themes = amo.utils.paginate(request, addons, count=count)
|
||||
themes = amo.utils.paginate(request, addons, count=addons.count())
|
||||
return jingo.render(request, 'browse/themes.html',
|
||||
{'categories': categories,
|
||||
'themes': themes, 'category': category,
|
||||
|
@ -160,8 +159,7 @@ def extensions(request, category=None, template=None):
|
|||
if category:
|
||||
addons = addons.filter(categories__id=category.id)
|
||||
|
||||
count = addons.with_index(addons='type_status_inactive_idx').count()
|
||||
addons = amo.utils.paginate(request, addons, count=count)
|
||||
addons = amo.utils.paginate(request, addons, count=addons.count())
|
||||
return jingo.render(request, template,
|
||||
{'category': category, 'addons': addons,
|
||||
'sorting': filter.field,
|
||||
|
@ -255,12 +253,9 @@ def personas_listing(request, category=None):
|
|||
def personas(request, category=None):
|
||||
categories, filter, base, category = personas_listing(request, category)
|
||||
|
||||
if category:
|
||||
count = category.count
|
||||
else:
|
||||
# Pass the count from base instead of letting it come from
|
||||
# filter.qs.count() since that would join against personas.
|
||||
count = base.with_index(addons='type_status_inactive_idx').count()
|
||||
# Pass the count from base instead of letting it come from
|
||||
# filter.qs.count() since that would join against personas.
|
||||
count = category.count if category else base.count()
|
||||
|
||||
if 'sort' in request.GET or count < 5:
|
||||
template = 'grid.html'
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
-- Create a version row for each persona.
|
||||
INSERT INTO versions (addon_id, version, created, modified)
|
||||
SELECT addons.id, 0, NOW(), NOW()
|
||||
FROM addons LEFT JOIN versions
|
||||
ON addons.id=versions.addon_id
|
||||
WHERE versions.id IS NULL;
|
||||
|
||||
-- Attach the current version for personas missing a current_version.
|
||||
UPDATE addons INNER JOIN
|
||||
(SELECT addons.id AS addon_id, versions.id AS version_id
|
||||
FROM addons INNER JOIN versions
|
||||
ON (addons.id = versions.addon_id
|
||||
AND addons.addontype_id = 9
|
||||
AND addons.current_version IS NULL)
|
||||
) AS J ON (addons.id = J.addon_id)
|
||||
SET addons.current_version = J.version_id;
|
|
@ -0,0 +1 @@
|
|||
CREATE INDEX visible_idx ON addons (addontype_id, status, inactive, current_version);
|
|
@ -77,6 +77,7 @@ HOME = /tmp
|
|||
25 1,13 * * * $REMORA; /usr/bin/python26 import-personas.py
|
||||
# Add slugs after we get all the new personas.
|
||||
25 2,14 * * * $Z_CRON addons_add_slugs
|
||||
45 2,14 * * * $Z_CRON give_personas_versions
|
||||
25 3,15 * * * $Z_CRON update_addons_collections_downloads
|
||||
25 8,20 * * * $Z_CRON update_collections_total
|
||||
25 9,21 * * * $Z_CRON hide_disabled_files
|
||||
|
|
|
@ -36,6 +36,7 @@ HOME = /tmp
|
|||
25 1,13 * * * cd /data/amo/www/addons.mozilla.org-preview/bin; /usr/bin/python26 import-personas.py
|
||||
# Add slugs after we get all the new personas.
|
||||
25 2,14 * * * cd /data/amo_python/src/preview/zamboni; /usr/bin/python26 manage.py cron addons_add_slugs
|
||||
45 2,14 * * * cd /data/amo_python/src/preview/zamboni; /usr/bin/python26 manage.py cron give_personas_versions
|
||||
25 3,15 * * * cd /data/amo_python/src/preview/zamboni; /usr/bin/python26 manage.py cron update_addons_collections_downloads
|
||||
25 8,20 * * * cd /data/amo_python/src/preview/zamboni; /usr/bin/python26 manage.py cron update_collections_total
|
||||
25 9,21 * * * cd /data/amo_python/src/preview/zamboni; /usr/bin/python26 manage.py cron hide_disabled_files
|
||||
|
|
|
@ -36,6 +36,7 @@ HOME = /tmp
|
|||
25 1,13 * * * apache cd /data/amo/www/addons.mozilla.org-remora/bin; /usr/bin/python26 import-personas.py
|
||||
# Add slugs after we get all the new personas.
|
||||
25 2,14 * * * apache cd /data/amo_python/src/prod/zamboni; /usr/bin/python26 manage.py cron addons_add_slugs
|
||||
45 2,14 * * * apache cd /data/amo_python/src/prod/zamboni; /usr/bin/python26 manage.py cron give_personas_versions
|
||||
25 3,15 * * * apache cd /data/amo_python/src/prod/zamboni; /usr/bin/python26 manage.py cron update_addons_collections_downloads
|
||||
25 8,20 * * * apache cd /data/amo_python/src/prod/zamboni; /usr/bin/python26 manage.py cron update_collections_total
|
||||
25 9,21 * * * apache cd /data/amo_python/src/prod/zamboni; /usr/bin/python26 manage.py cron hide_disabled_files
|
||||
|
|
Загрузка…
Ссылка в новой задаче