mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-10 00:42:06 +00:00
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:
@ -1,2 +1,5 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from models import DocPageAlias
|
||||
|
||||
admin.site.register(DocPageAlias)
|
||||
|
27
pgweb/docs/migrations/0003_docs_alias.py
Normal file
27
pgweb/docs/migrations/0003_docs_alias.py
Normal file
@ -0,0 +1,27 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('docs', '0002_drop_doccomments'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='DocPageAlias',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('file1', models.CharField(unique=True, max_length=64)),
|
||||
('file2', models.CharField(unique=True, max_length=64)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'docsalias',
|
||||
'verbose_name_plural': 'Doc page aliases',
|
||||
},
|
||||
),
|
||||
migrations.RunSQL("CREATE UNIQUE INDEX docsalias_unique ON docsalias (LEAST(file1, file2), GREATEST(file1, file2))"),
|
||||
]
|
@ -20,3 +20,15 @@ class DocPage(models.Model):
|
||||
db_table = 'docs'
|
||||
# Index file first, because we want to list versions by file
|
||||
unique_together = [('file', 'version')]
|
||||
|
||||
class DocPageAlias(models.Model):
|
||||
file1 = models.CharField(max_length=64, null=False, blank=False, unique=True)
|
||||
file2 = models.CharField(max_length=64, null=False, blank=False, unique=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s <-> %s" % (self.file1, self.file2)
|
||||
|
||||
# XXX: needs a unique functional index as well, see the migration!
|
||||
class Meta:
|
||||
db_table = 'docsalias'
|
||||
verbose_name_plural='Doc page aliases'
|
||||
|
@ -54,7 +54,11 @@ 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={
|
||||
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')
|
||||
|
Reference in New Issue
Block a user