mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-25 22:03:10 +00:00
Mise en cache de l'instance en entier, supprime les clefs foireuses
This commit is contained in:
parent
3868a9614f
commit
543c65bd50
3 changed files with 72 additions and 51 deletions
|
@ -69,18 +69,17 @@ class OptionalUser(models.Model):
|
|||
)
|
||||
|
||||
@classmethod
|
||||
def set_in_cache(cls, key):
|
||||
machine_options, _created = cls.objects.get_or_create()
|
||||
value = getattr(machine_options, key)
|
||||
cache.set('optionaluser_' + key, value, None)
|
||||
return value
|
||||
def set_in_cache(cls):
|
||||
optionaluser, _created = cls.objects.get_or_create()
|
||||
cache.set('optionaluser', optionaluser, None)
|
||||
return optionaluser
|
||||
|
||||
@classmethod
|
||||
def get_cached_value(cls, key):
|
||||
value = cache.get('optionaluser_' + key)
|
||||
if value == None:
|
||||
value = cls.set_in_cache(key)
|
||||
return value
|
||||
optionaluser = cache.get('optionaluser')
|
||||
if optionaluser == None:
|
||||
optionaluser = cls.set_in_cache()
|
||||
return getattr(optionaluser, key)
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
|
@ -148,6 +147,13 @@ class OptionalUser(models.Model):
|
|||
c.save()
|
||||
|
||||
|
||||
@receiver(post_save, sender=OptionalUser)
|
||||
def optionaluser_post_save(sender, **kwargs):
|
||||
"""Ecriture dans le cache"""
|
||||
user_pref = kwargs['instance']
|
||||
user_pref.set_in_cache()
|
||||
|
||||
|
||||
class OptionalMachine(models.Model):
|
||||
"""Options pour les machines : maximum de machines ou d'alias par user
|
||||
sans droit, activation de l'ipv6"""
|
||||
|
@ -176,18 +182,17 @@ class OptionalMachine(models.Model):
|
|||
return not self.get_cached_value('ipv6_mode') == 'DISABLED'
|
||||
|
||||
@classmethod
|
||||
def set_in_cache(cls, key):
|
||||
machine_options, _created = cls.objects.get_or_create()
|
||||
value = getattr(machine_options, key)
|
||||
cache.set('optionalmachine_' + key, value, None)
|
||||
return value
|
||||
def set_in_cache(cls):
|
||||
optionalmachine, _created = cls.objects.get_or_create()
|
||||
cache.set('optionalmachine', optionalmachine, None)
|
||||
return optionalmachine
|
||||
|
||||
@classmethod
|
||||
def get_cached_value(cls, key):
|
||||
value = cache.get('optionalmachine_' + key)
|
||||
if value == None:
|
||||
value = cls.set_in_cache(key)
|
||||
return value
|
||||
optionalmachine = cache.get('optionalmachine')
|
||||
if optionalmachine == None:
|
||||
optionalmachine = cls.set_in_cache()
|
||||
return getattr(optionalmachine, key)
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
|
@ -250,9 +255,9 @@ class OptionalMachine(models.Model):
|
|||
|
||||
@receiver(post_save, sender=OptionalMachine)
|
||||
def optionalmachine_post_save(sender, **kwargs):
|
||||
"""Synchronisation ipv6"""
|
||||
"""Synchronisation ipv6 et ecriture dans le cache"""
|
||||
machine_pref = kwargs['instance']
|
||||
|
||||
machine_pref.set_in_cache()
|
||||
if machine_pref.ipv6_mode != "DISABLED":
|
||||
for interface in machines.models.Interface.objects.all():
|
||||
interface.sync_ipv6()
|
||||
|
@ -291,18 +296,17 @@ class OptionalTopologie(models.Model):
|
|||
)
|
||||
|
||||
@classmethod
|
||||
def set_in_cache(cls, key):
|
||||
machine_options, _created = cls.objects.get_or_create()
|
||||
value = getattr(machine_options, key)
|
||||
cache.set('optionaltopologie_' + key, value, None)
|
||||
return value
|
||||
def set_in_cache(cls):
|
||||
optionaltopologie, _created = cls.objects.get_or_create()
|
||||
cache.set('optionaltopologie', optionaltopologie, None)
|
||||
return optionaltopologie
|
||||
|
||||
@classmethod
|
||||
def get_cached_value(cls, key):
|
||||
value = cache.get('optionaltopologie_' + key)
|
||||
if value == None:
|
||||
value = cls.set_in_cache(key)
|
||||
return value
|
||||
optionaltopologie = cache.get('optionaltopologie')
|
||||
if optionaltopologie == None:
|
||||
optionaltopologie = cls.set_in_cache()
|
||||
return getattr(optionaltopologie, key)
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
|
@ -362,6 +366,13 @@ class OptionalTopologie(models.Model):
|
|||
de voir les préférences concernant la topologie"
|
||||
|
||||
|
||||
@receiver(post_save, sender=OptionalTopologie)
|
||||
def optionaltopologie_post_save(sender, **kwargs):
|
||||
"""Ecriture dans le cache"""
|
||||
topologie_pref = kwargs['instance']
|
||||
topologie_pref.set_in_cache()
|
||||
|
||||
|
||||
class GeneralOption(models.Model):
|
||||
"""Options générales : nombre de resultats par page, nom du site,
|
||||
temps où les liens sont valides"""
|
||||
|
@ -390,18 +401,17 @@ class GeneralOption(models.Model):
|
|||
)
|
||||
|
||||
@classmethod
|
||||
def set_in_cache(cls, key):
|
||||
machine_options, _created = cls.objects.get_or_create()
|
||||
value = getattr(machine_options, key)
|
||||
cache.set('generaloption_' + key, value, None)
|
||||
return value
|
||||
def set_in_cache(cls):
|
||||
generaloption, _created = cls.objects.get_or_create()
|
||||
cache.set('generaloption', generaloption, None)
|
||||
return generaloption
|
||||
|
||||
@classmethod
|
||||
def get_cached_value(cls, key):
|
||||
value = cache.get('generaloption_' + key)
|
||||
if value == None:
|
||||
value = cls.set_in_cache(key)
|
||||
return value
|
||||
generaloption = cache.get('generaloption')
|
||||
if generaloption == None:
|
||||
generaloption = cls.set_in_cache()
|
||||
return getattr(generaloption, key)
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
|
@ -462,6 +472,13 @@ class GeneralOption(models.Model):
|
|||
de voir les préférences générales"
|
||||
|
||||
|
||||
@receiver(post_save, sender=GeneralOption)
|
||||
def generaloption_post_save(sender, **kwargs):
|
||||
"""Ecriture dans le cache"""
|
||||
general_pref = kwargs['instance']
|
||||
general_pref.set_in_cache()
|
||||
|
||||
|
||||
class Service(models.Model):
|
||||
"""Liste des services affichés sur la page d'accueil : url, description,
|
||||
image et nom"""
|
||||
|
@ -572,18 +589,17 @@ class AssoOption(models.Model):
|
|||
)
|
||||
|
||||
@classmethod
|
||||
def set_in_cache(cls, key):
|
||||
machine_options, _created = cls.objects.get_or_create()
|
||||
value = getattr(machine_options, key)
|
||||
cache.set('assooption_' + key, value, None)
|
||||
return value
|
||||
def set_in_cache(cls):
|
||||
assooption, _created = cls.objects.get_or_create()
|
||||
cache.set('assooption', assooption, None)
|
||||
return assooption
|
||||
|
||||
@classmethod
|
||||
def get_cached_value(cls, key):
|
||||
value = cache.get('assooption_' + key)
|
||||
if value == None:
|
||||
value = cls.set_in_cache(key)
|
||||
return value
|
||||
assooption = cache.get('assooption')
|
||||
if assooption == None:
|
||||
assooption = cls.set_in_cache()
|
||||
return getattr(assooption, key)
|
||||
|
||||
class Meta:
|
||||
permissions = (
|
||||
|
@ -643,6 +659,13 @@ class AssoOption(models.Model):
|
|||
de voir les préférences concernant l'association"
|
||||
|
||||
|
||||
@receiver(post_save, sender=AssoOption)
|
||||
def assooption_post_save(sender, **kwargs):
|
||||
"""Ecriture dans le cache"""
|
||||
asso_pref = kwargs['instance']
|
||||
asso_pref.set_in_cache()
|
||||
|
||||
|
||||
class MailMessageOption(models.Model):
|
||||
"""Reglages, mail de bienvenue et autre"""
|
||||
PRETTY_NAME = "Options de corps de mail"
|
||||
|
|
|
@ -364,8 +364,7 @@ def new_switch(request):
|
|||
request.POST or None,
|
||||
)
|
||||
if switch.is_valid() and machine.is_valid() and interface.is_valid():
|
||||
options, _created = AssoOption.objects.get_or_create()
|
||||
user = options.utilisateur_asso
|
||||
user = AssoOption.get_cached_value('utilisateur_asso')
|
||||
if not user:
|
||||
messages.error(request, "L'user association n'existe pas encore,\
|
||||
veuillez le créer ou le linker dans preferences")
|
||||
|
|
|
@ -701,7 +701,6 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
|||
else:
|
||||
return False, u"Vous n'avez pas le droit d'éditer ce club"
|
||||
else:
|
||||
options, _created = AssoOption.objects.get_or_create()
|
||||
if self == user_request:
|
||||
return True, None
|
||||
elif user_request.has_perm('users.change_all_users'):
|
||||
|
@ -709,7 +708,7 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
|||
elif user_request.has_perm('users.change_user'):
|
||||
if self.groups.filter(listright__critical=True):
|
||||
return False, u"Utilisateurs avec droits critiques, ne peut etre édité"
|
||||
elif self == options.utilisateur_asso:
|
||||
elif self == AssoOption.get_cached_value('utilisateur_asso'):
|
||||
return False, u"Impossible d'éditer l'utilisateur asso sans droit change_all_users"
|
||||
else:
|
||||
return True, None
|
||||
|
|
Loading…
Reference in a new issue