record the min/max appversion in appsupport

This commit is contained in:
Jeff Balogh 2011-03-10 10:06:32 -08:00
Родитель 84481fe2a6
Коммит e91f3a3ada
4 изменённых файлов: 29 добавлений и 7 удалений

Просмотреть файл

@ -19,7 +19,7 @@ from celeryutils import task
import amo
import cronjobs
from amo.utils import chunked
from addons.models import Addon, FrozenAddon
from addons.models import Addon, FrozenAddon, AppSupport
from addons.utils import ReverseNameLookup
from files.models import File
from stats.models import UpdateCount
@ -215,6 +215,14 @@ def update_addon_appsupport():
_update_appsupport.apply_async(args=[chunk], connection=conn)
@cronjobs.register
def update_all_appsupport():
from .tasks import update_appsupport
ids = set(AppSupport.objects.values_list('addon', flat=True))
for chunk in chunked(ids, 100):
update_appsupport(chunk)
@task(rate_limit='30/m')
@transaction.commit_manually
def _update_appsupport(ids, **kw):

Просмотреть файл

@ -1285,6 +1285,8 @@ class AppSupport(amo.models.ModelBase):
"""Cache to tell us if an add-on's current version supports an app."""
addon = models.ForeignKey(Addon)
app = models.ForeignKey('applications.Application')
min = models.BigIntegerField("Minimum app version", null=True)
max = models.BigIntegerField("Maximum app version", null=True)
class Meta:
db_table = 'appsupport'

Просмотреть файл

@ -36,17 +36,25 @@ def update_last_updated(addon_id):
Addon.objects.filter(pk=pk).update(last_updated=t)
@transaction.commit_manually
@transaction.commit_on_success
def update_appsupport(ids):
log.info("[%s@None] Updating appsupport for %s." % (len(ids), ids))
delete = 'DELETE FROM appsupport WHERE addon_id IN (%s)'
insert = """INSERT INTO appsupport (addon_id, app_id, created, modified)
insert = """INSERT INTO appsupport
(addon_id, app_id, min, max, created, modified)
VALUES %s"""
addons = Addon.uncached.filter(id__in=ids).no_transforms()
apps = [(addon.id, app.id) for addon in addons
for app in addon.compatible_apps]
s = ','.join('(%s, %s, NOW(), NOW())' % x for x in apps)
apps = []
for addon in addons:
for app, appver in addon.compatible_apps.items():
if appver is None:
# Fake support for all version ranges.
min_, max_ = 0, 999999999999999999
else:
min_, max_ = appver.min.version_int, appver.max.version_int
apps.append((addon.id, app.id, min_, max_))
s = ','.join('(%s, %s, %s, %s, NOW(), NOW())' % x for x in apps)
if not apps:
return
@ -54,7 +62,6 @@ def update_appsupport(ids):
cursor = connection.cursor()
cursor.execute(delete % ','.join(map(str, ids)))
cursor.execute(insert % s)
transaction.commit()
# All our updates were sql, so invalidate manually.
Addon.objects.invalidate(*addons)

Просмотреть файл

@ -0,0 +1,5 @@
ALTER TABLE appsupport
ADD COLUMN `min` bigint(20) unsigned DEFAULT NULL,
ADD COLUMN `max` bigint(20) unsigned DEFAULT NULL;
CREATE INDEX minmax_idx ON appsupport (addon_id, app_id, min, max);