mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
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:
1 parent
28143c091a
commit
daabeccb60
6 files changed
+200
-29
No files matched your search
+8
-4
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user