-
Notifications
You must be signed in to change notification settings - Fork 13
/
performance.txt
30 lines (22 loc) · 1.02 KB
/
performance.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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.