From 7b6a066b91d0dc9b165ae97205a936f376d92417 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Wed, 28 Jan 2026 16:10:30 +0000 Subject: [PATCH] update only changed fields optimisation now done --- core/models/wallets.py | 2 +- parsers/survex.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/core/models/wallets.py b/core/models/wallets.py index 4567312..5e1538e 100644 --- a/core/models/wallets.py +++ b/core/models/wallets.py @@ -329,7 +329,7 @@ class Wallet(models.Model): return None else: self.walletyear = datetime.date(year, 1, 1) - self.save() + self.save(update_fields=["walletdate"]) return str(year) # Yes this is horribly, horribly inefficient, esp. for a page that have date, people and cave in it diff --git a/parsers/survex.py b/parsers/survex.py index c6acb16..031d9e0 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -106,7 +106,7 @@ def set_walletdate(w): if not w.date(): # sets .walletdate as a side-effect if it gets it from JSON d = datewallet(w, earliest) # Not in JSON, so checks all the survex blocks w.walletdate = d - w.save() + w.save(update_fields=["walletdate"]) def stash_data_issue(parser=None, message=None, url=None, sb=None): """Avoid hitting the database for error messages until the end of the import @@ -1212,7 +1212,7 @@ class LoadingSurvex: Currently this just sets a flag that the survex block is not CUCC """ survexblock.foreigners = True - survexblock.save() + survexblock.save(update_fields=["foreigners"]) def LoadSurvexRef(self, survexblock, args): """Interpret the *ref record, and all the many variants @@ -1303,8 +1303,9 @@ class LoadingSurvex: else: survexblock.scanswallet = manywallets[0] # this is a ForeignKey field - survexblock.save() - # This is where we chould check that the wallet JSON contains a link to the survexfile + # Only save if changed + survexblock.save(update_fields=["scanswallet"]) + # This is where we should check that the wallet JSON contains a link to the survexfile # and that the JSON date and walletdate are set correctly to the survexblock date. set_walletdate(survexblock.scanswallet) else: @@ -1555,7 +1556,7 @@ class LoadingSurvex: # print(f"\n - New directory '{newdirectory}' for cave '{cave}'",file=sys.stderr) if not cave.survex_file: cave.survex_file = svxid + ".svx" - cave.save() + cave.save(update_fields=["survex_file"]) # message = f" - '{cave}' had no survex_file set - setting '{svxid}.svx' writing to {cave.filename})" message = f" - '{cave}' has no survex_file set - need to set to '{svxid}.svx' in {cave.filename})" print("\n",message,file=sys.stderr) @@ -2739,7 +2740,7 @@ def parse_one_file(fpath): # --------------------------------------in progress-- cave_svxpath = cave.survex_file[:-4] # remove .svx else: cave.survex_file = svxpath + ".svx" - cave.save() + cave.save(update_fields=["survex_file"]) cave_svxpath = svxpath try: fileroot = SurvexFile.objects.get(path=cave_svxpath)