Revert "*temporary commit* for load testing, will be reverted"

This reverts commit c7712b6596.
This commit is contained in:
Andy McKay 2011-02-02 13:44:30 -08:00
Родитель 8f4ff1b41c
Коммит 23ec571b45
5 изменённых файлов: 59 добавлений и 121 удалений

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

@ -1,27 +1,27 @@
<?xml version="1.0"?>
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
{% if row.version %}
<RDF:Description about="urn:mozilla:{{ row.type }}:{{ row.guid }}">
{% if version %}
<RDF:Description about="urn:mozilla:{{ type }}:{{ addon.guid }}">
<em:updates>
<RDF:Seq>
<RDF:li resource="urn:mozilla:{{ row.type }}:{{ row.guid }}:{{ row.version }}"/>
<RDF:li resource="urn:mozilla:{{ type }}:{{ addon.guid }}:{{ version.version }}"/>
</RDF:Seq>
</em:updates>
</RDF:Description>
<RDF:Description about="urn:mozilla:{{ row.type }}:{{ row.guid }}:{{ row.version }}">
<em:version>{{ row.version }}</em:version>
<RDF:Description about="urn:mozilla:{{ type }}:{{ addon.guid }}:{{ version.version }}">
<em:version>{{ version.version }}</em:version>
<em:targetApplication>
<RDF:Description>
<em:id>{{ row.appguid }}</em:id>
<em:minVersion>{{ row.min }}</em:minVersion>
<em:maxVersion>{{ row.max }}</em:maxVersion>
<em:updateLink>{{ row.uri }}</em:updateLink>
{% if row.releasenotes %}
<em:updateInfoURL>{{ settings.SITE_URL }}{{ remora_url('/versions/updateInfo/%s/' % row.version) }}%APP_LOCALE%/</em:updateInfoURL>
<em:id>{{ application.guid }}</em:id>
<em:minVersion>{{ application_version.min }}</em:minVersion>
<em:maxVersion>{{ application_version.max }}</em:maxVersion>
<em:updateLink>{{ url }}</em:updateLink>
{% if version.releasenotes %}
<em:updateInfoURL>{{ settings.SITE_URL }}{{ remora_url('/versions/updateInfo/%s/' % version.pk) }}%APP_LOCALE%/</em:updateInfoURL>
{% endif %}
{% if row.hash %}
<em:updateHash>{{ row.hash }}</em:updateHash>
{% if file.hash %}
<em:updateHash>{{ file.hash }}</em:updateHash>
{% endif %}
</RDF:Description>
</em:targetApplication>

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

@ -1091,7 +1091,7 @@ class TestUpdate(test_utils.TestCase):
data = self.good_data.copy()
data["appOS"] = self.win.shortname
res = self.client.get(self.url, data)
eq_(res.context['row']['file_id'], file.pk)
eq_(res.context['file'].pk, file.pk)
data["appOS"] = self.mac.shortname
res = self.client.get(self.url, data)
@ -1111,18 +1111,18 @@ class TestUpdate(test_utils.TestCase):
data = self.good_data.copy()
data['appOS'] = self.win.shortname
res = self.client.get(self.url, data)
eq_(res.context['row']['file_id'], file_pk)
eq_(res.context['file'].id, file_pk)
data['appOS'] = self.mac.shortname
res = self.client.get(self.url, data)
eq_(res.context['row']['file_id'], mac_file_pk)
eq_(res.context['file'].id, mac_file_pk)
def test_good_version(self):
res = self.client.get(self.url, self.good_data)
eq_(res.status_code, 200)
assert res.context['row']['hash'].startswith('sha256:3808b13e')
eq_(res.context['row']['min'], '2.0')
eq_(res.context['row']['max'], '3.7a1pre')
assert res.context['file'].hash.startswith('sha256:3808b13e')
eq_(res.context['application_version'].min.version, '2.0')
eq_(res.context['application_version'].max.version, '3.7a1pre')
def test_beta_version(self):
file = File.objects.get(pk=67442)
@ -1141,7 +1141,7 @@ class TestUpdate(test_utils.TestCase):
data["version"] = beta_version
res = self.client.get(self.url, data)
eq_(res.context['row']['file_id'], file.pk)
eq_(res.context['file'].id, file.pk)
def test_no_app_version(self):
data = self.good_data.copy()
@ -1155,9 +1155,9 @@ class TestUpdate(test_utils.TestCase):
data['appVersion'] = '2.0'
res = self.client.get(self.url, data)
eq_(res.status_code, 200)
assert res.context['row']['hash'].startswith('sha256:3808b13e')
eq_(res.context['row']['min'], '2.0')
eq_(res.context['row']['max'], '3.7a1pre')
assert res.context['file'].hash.startswith('sha256:3808b13e')
eq_(res.context['application_version'].min.version, '2.0')
eq_(res.context['application_version'].max.version, '3.7a1pre')
def test_content_type(self):
res = self.client.get(self.url, self.good_data)
@ -1167,15 +1167,15 @@ class TestUpdate(test_utils.TestCase):
res = self.client.get(self.url, self.good_data)
assert res.content.find(self.good_data['appID']) > -1
# def test_url(self):
# res = self.client.get(self.url, self.good_data)
# assert settings.MIRROR_URL in res.context['row']['uri']
def test_url(self):
res = self.client.get(self.url, self.good_data)
assert settings.MIRROR_URL in res.context['url']
# def test_url_local_recent(self):
# a_bit_ago = datetime.now() - timedelta(seconds=60)
# File.objects.get(pk=67442).update(datestatuschanged=a_bit_ago)
# res = self.client.get(self.url, self.good_data)
# assert settings.LOCAL_MIRROR_URL in res.context['url']
def test_url_local_recent(self):
a_bit_ago = datetime.now() - timedelta(seconds=60)
File.objects.get(pk=67442).update(datestatuschanged=a_bit_ago)
res = self.client.get(self.url, self.good_data)
assert settings.LOCAL_MIRROR_URL in res.context['url']
def test_url_remote_beta(self):
file = File.objects.get(pk=67442)
@ -1190,9 +1190,9 @@ class TestUpdate(test_utils.TestCase):
data = self.good_data.copy()
data["version"] = beta_version
res = self.client.get(self.url, data)
eq_(res.context['row']['file_id'], file.pk)
eq_(res.context['file'].id, file.pk)
#assert settings.MIRROR_URL in res.context['url']
assert settings.MIRROR_URL in res.context['url']
def test_hash(self):
res = self.client.get(self.url, self.good_data)
@ -1216,17 +1216,17 @@ class TestUpdate(test_utils.TestCase):
eq_(res.content.find('updateInfoURL'), -1)
def test_sea_monkey(self):
data = {'id': 'bettergmail2@ginatrapani.org',
data = {
'id': 'bettergmail2@ginatrapani.org',
'version': '1',
'appID': '{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}',
'reqVersion': 1,
'appVersion': '1.0',
}
res = self.client.get(reverse('addons.update'), data)
assert res.context['row']['hash'].startswith('sha256:9d9a389')
eq_(res.context['row']['min'], '1.0')
eq_(res.context['row']['version'], '0.5.2')
assert res.context['file'].hash.startswith('sha256:9d9a389')
eq_(res.context['application_version'].min.version, '1.0')
eq_(res.context['application_version'].version.version, '0.5.2')
assert res.content.find(data['appID']) > -1

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

@ -56,4 +56,6 @@ urlpatterns = patterns('',
addon_id, permanent=True)),
('^versions/license/(\d+)$', views.license_redirect),
url('^services/update$', views.update, name='addons.update'),
)

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

@ -3,8 +3,6 @@ import random
import uuid
from operator import attrgetter
from django.db import connection
from django.utils.datastructures import SortedDict
from django import http
from django.conf import settings
from django.db.models import Q
@ -29,7 +27,6 @@ from amo.models import manual_order
from amo import urlresolvers
from amo.urlresolvers import reverse
from bandwagon.models import Collection, CollectionFeature, CollectionPromo
from files.models import File
from reviews.forms import ReviewForm
from reviews.models import Review
from sharing.views import share as share_redirect
@ -548,87 +545,28 @@ def report_abuse(request, addon):
@cache_page(3600)
def update(request):
query, row = SortedDict(), {}
form = UpdateForm(request.GET)
if form.is_valid():
data = form.cleaned_data
query['id'] = data['id'].pk
query['app_id'] = form.cleaned_data['appID'].guid
query['platform'] = amo.PLATFORM_ALL.id
app_os = data.get('appOS')
if app_os:
query['specific_platform'] = app_os.id
query['status'] = amo.STATUS_PUBLIC
if form.cleaned_data['id'].status == amo.STATUS_PUBLIC:
if form.is_beta_version:
version = data['version']
files = File.objects.filter(version__version=version,
version__addon=query['id'])[:1]
if files and files[0].status:
query['status'] = files[0].status
else:
query['status'] = amo.STATUS_NULL
query['version'] = data['version']
query['max'] = query['min'] = form.version_int
# This raw SQL query is a port of the remora code, it is retained
# as raw SQL as the simplest route. Although there
# is possible room for optimisation here.
sql = """
SELECT
addons.guid as guid, addons.addontype_id as type,
applications.guid as appguid,
appmin.version as min, appmax.version as max,
files.id as file_id, files.hash, files.filename,
versions.id as version_id, versions.releasenotes,
versions.version as version
FROM versions
INNER JOIN addons
ON addons.id = versions.addon_id AND addons.id = %s
INNER JOIN applications_versions
ON applications_versions.version_id = versions.id
INNER JOIN applications
ON applications_versions.application_id = applications.id
AND applications.guid = %s
INNER JOIN appversions appmin
ON appmin.id = applications_versions.min
INNER JOIN appversions appmax
ON appmax.id = applications_versions.max
INNER JOIN files
ON files.version_id = versions.id AND (files.platform_id = %s
"""
if 'specific_platform' in query:
sql += ' OR files.platform_id = %s'
if 'version' in query:
sql += ') WHERE files.status > %s AND versions.version = %s '
else:
sql += ') WHERE files.status = %s '
sql += """
AND (appmin.version_int >= %s OR appmax.version_int <= %s)
ORDER BY
appmax.version_int DESC,
versions.id DESC
LIMIT 1"""
cursor = connection.cursor()
cursor.execute(sql, query.values())
result = cursor.fetchone()
if result:
row = dict(zip(['guid', 'type', 'appguid', 'min', 'max',
'file_id', 'hash', 'filename', 'version_id',
'releasenotes', 'version'],
list(result)))
uri = reverse('downloads.file', args=[row['file_id'],
row['filename']])
row['uri'] = absolutify(uri)
row['type'] = amo.ADDON_SLUGS_UPDATE.get(row['type'])
version, file = data['id'].get_current_version_for_client(
data['version'], form.version_int,
data['appID'], data['appOS'])
if version and file:
app = amo.APP_IDS[data['appID'].id]
application_version = version.compatible_apps[app]
addon_type = amo.ADDON_SLUGS_UPDATE[data['id'].type]
url = file.get_mirror(data['id'])
return jingo.render(request, 'addons/update.rdf', {
'addon': data['id'],
'application': data['appID'],
'application_version': application_version,
'appversion': data['appVersion'],
'file': file,
'type': addon_type,
'url': url,
'version': version,
}, content_type="text/xml")
return jingo.render(request, 'addons/update.rdf',
{'query': query, 'row': row},
content_type="text/xml")
{}, content_type="text/xml")

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

@ -15,8 +15,6 @@ handler500 = 'amo.views.handler500'
urlpatterns = patterns('',
# Discovery pane is first for undetectable efficiency wins.
('^discovery/', include('discovery.urls')),
# Claiming second, because there's a real win here.
url('^services/update$', 'addons.views.update', name='addons.update'),
# Add-ons.
('', include('addons.urls')),