Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

30 lines (22 sloc) 1.045 kb
# query
where = '{comparator_table}.{comparator} = (SELECT MAX({comparator}) FROM {table} as sub WHERE {table}.cid = sub.cid)'
# optimized query
where = '{comparator_table}.{pk} IN {comparator_table}_latest_revisions'
# in the code
# optimize by default
if not getattr(settings, 'OPTIMIZE_REVISIONS', True):
where
else:
optimized_where
# post-syncdb
for model in versioned_models:
base = model.get_base_model()
table = base._meta.db_table + "_latest_revisions"
pk = model().pk_name
latest = str(model.latest.only(pk).query)
sql = "CREATE OR REPLACE VIEW {table} AS {selection}".format(
table=table,
selection=latest
)
# NOTE TO SELF: create a script that enters ~20k records into a DB and test performance before committing this
# If this still isn't fast enough, we could actually go for a real, indexed table, but then we have to take care of keeping the _latest_revisions table in sync with the real table, which isn't rocket science but which I'd rather avoid.
Jump to Line
Something went wrong with that request. Please try again.