Invent the concept of a docs page alias

This allows us to say that "app-pgreceivexlog.html" is actually the same
as "app-pgreceivewal.html" on a different version.

Turns out the templates would already render this correctly if we could
just find the map, so it's a simple case of adding an additional join
(that the django orm can't figure out, but we can do it in manual sql).

Adds a non-django managed unique index to make sure that it's not
possible to add the same alias twice in different "directions".
Violating this will cause a django excpetion in the admin interface
since it doesn't know about it, but as this is a very uncommon operation
and admin only, we don't care about that.

Finally, we don't bother issuing varnish purges for changes here, the
admin is expected to handle those manually. These changes are supposed
to happen very seldom, and the contents are purged automatically when
the docs are loaded anyway.
This commit is contained in:
Magnus Hagander
2017-05-25 11:28:39 -04:00
parent 0585a97556
commit 496416ceda
4 changed files with 49 additions and 3 deletions

View File

@ -54,9 +54,13 @@ def docpage(request, version, typ, filename):
fullname = "%s.%s" % (filename, extension)
page = get_object_or_404(DocPage, version=ver, file=fullname)
versions = DocPage.objects.filter(file=fullname).extra(select={
'supported':"COALESCE((SELECT supported FROM core_version v WHERE v.tree=version), 'f')",
'testing':"COALESCE((SELECT testing FROM core_version v WHERE v.tree=version),0)",
qq = Q(file=fullname) | Q(file='kalle.html')
versions = DocPage.objects.extra(
where=["file=%s OR file IN (SELECT file2 FROM docsalias WHERE file1=%s) OR file IN (SELECT file1 FROM docsalias WHERE file2=%s)"],
params=[fullname, fullname, fullname],
select={
'supported':"COALESCE((SELECT supported FROM core_version v WHERE v.tree=version), 'f')",
'testing':"COALESCE((SELECT testing FROM core_version v WHERE v.tree=version),0)",
}).order_by('-supported', '-version').only('version', 'file')
if typ=="interactive":