db: Serialize most of the database queries using locks

See db.py for rationale.

Tests:

- Run functional tests and unit tests.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2023-10-23 12:40:13 -04:00
1 parent 28143c091a
commit daabeccb60
6 files changed
+200 -29

No files matched your search

+8 -4
View File
@@ -11,6 +11,8 @@ from django.core.exceptions import ValidationError
from django.db import models
from django.dispatch import receiver
from . import db
class KVStore(models.Model):
"""Model to store retrieve key/value configuration"""
@@ -45,14 +47,16 @@ class UserProfile(models.Model):
@receiver(models.signals.post_save, sender=User)
def _on_user_post_save(sender, instance, **kwargs):
"""When the user model is saved, user profile too."""
if hasattr(instance, 'userprofile'):
instance.userprofile.save()
else:
UserProfile.objects.update_or_create(user=instance)
with db.lock:
if hasattr(instance, 'userprofile'):
instance.userprofile.save()
else:
UserProfile.objects.update_or_create(user=instance)
class JSONField(models.TextField):
"""Store and retrieve JSON data into a TextField."""
def to_python(self, value):
"""Deserialize a text string from form field to Python dict."""
if not value: