summaryrefslogtreecommitdiffstats
path: root/packages/models.py
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-07-08 00:28:02 +0200
committerDan McGee <dan@archlinux.org>2012-07-09 04:08:04 +0200
commit26a00cadcebc0b37775954d261ec73f927ceca12 (patch)
tree8a1246c72e014a92d6b4b98055b37d770e970812 /packages/models.py
parent4cd588ae898c2abc8035cf0165ccdd038f2321bd (diff)
downloadarchweb-26a00cadcebc0b37775954d261ec73f927ceca12.tar.gz
archweb-26a00cadcebc0b37775954d261ec73f927ceca12.tar.xz
Don't log package updates in Python when we have DB trigger support
This adds a helper method to find the database engine in use, and then skips code we shouldn't execute if we are doing this another way. Note that this helper method could be useful for backend-specific code paths elsewhere, such as custom SQL being called or lack of StdDev() in sqlite3 out of the box. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'packages/models.py')
-rw-r--r--packages/models.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/packages/models.py b/packages/models.py
index 2f03a28..45ff3c0 100644
--- a/packages/models.py
+++ b/packages/models.py
@@ -6,7 +6,7 @@ from django.contrib.admin.models import ADDITION, CHANGE, DELETION
from django.contrib.auth.models import User
from main.models import Arch, Repo, Package
-from main.utils import set_created_field
+from main.utils import set_created_field, database_vendor
class PackageRelation(models.Model):
@@ -207,7 +207,12 @@ class UpdateManager(models.Manager):
def log_update(self, old_pkg, new_pkg):
'''Utility method to help log an update. This will determine the type
based on how many packages are passed in, and will pull the relevant
- necesary fields off the given packages.'''
+ necesary fields off the given packages.
+ Note that in some cases, this is a no-op if we know this database type
+ supports triggers to add these rows instead.'''
+ if database_vendor(Package, 'write') in ('sqlite', 'postgresql'):
+ # we log updates using database triggers for these backends
+ return
update = Update()
if new_pkg:
update.action_flag = ADDITION
@@ -222,6 +227,12 @@ class UpdateManager(models.Manager):
if old_pkg:
if new_pkg:
update.action_flag = CHANGE
+ # ensure we should even be logging this
+ if (old_pkg.pkgver == new_pkg.pkgver and
+ old_pkg.pkgrel == new_pkg.pkgrel and
+ old_pkg.epoch == new_pkg.epoch):
+ # all relevant fields were the same; e.g. a force update
+ return
else:
update.action_flag = DELETION
update.arch = old_pkg.arch