Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some pseudocode indicating a possible performance improvement. …
…Removed use_for_related_fields = True from the manager, which I think is a vestige from old code that doesn't actually make sense anymore.
- Loading branch information
1 parent
d52da90
commit b256b91
Showing
3 changed files
with
36 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters