OpenSlides/openslides/topics/models.py
Oskar Hahn dd4754d045 Disable the future-lock when updating the restircted data cache
Before this commit, there where two different locks when updating the restricted
data cache. A future lock, what is faster but only works in the same thread. The
other lock is in redis, it is not so fast, but also works in many threads.

The future lock was buggy, because on a second call of update_restricted_data
the same future was reused. So on the second run, the future was already done.

I don't see any way to delete. The last client would have to delete it, but there
is no way to find out which client the last one is.
2019-03-04 21:37:00 +01:00

72 lines
2.0 KiB
Python

from typing import Any, Dict
from django.contrib.contenttypes.fields import GenericRelation
from django.db import models
from .access_permissions import TopicAccessPermissions
from ..agenda.models import Item
from ..mediafiles.models import Mediafile
from ..utils.models import RESTModelMixin
class TopicManager(models.Manager):
"""
Customized model manager to support our get_full_queryset method.
"""
def get_full_queryset(self):
"""
Returns the normal queryset with all topics. In the background all
attachments and the related agenda item are prefetched from the
database.
"""
return self.get_queryset().prefetch_related("attachments", "agenda_items")
class Topic(RESTModelMixin, models.Model):
"""
Model for slides with custom content. Used to be called custom slide.
"""
access_permissions = TopicAccessPermissions()
objects = TopicManager()
title = models.CharField(max_length=256)
text = models.TextField(blank=True)
attachments = models.ManyToManyField(Mediafile, blank=True)
# In theory there could be one then more agenda_item. But we support only
# one. See the property agenda_item.
agenda_items = GenericRelation(Item, related_name="topics")
class Meta:
default_permissions = ()
def __str__(self):
return self.title
"""
Container for runtime information for agenda app (on create or update of this instance).
"""
agenda_item_update_information: Dict[str, Any] = {}
@property
def agenda_item(self):
"""
Returns the related agenda item.
"""
# We support only one agenda item so just return the first element of
# the queryset.
return self.agenda_items.all()[0]
@property
def agenda_item_id(self):
"""
Returns the id of the agenda item object related to this object.
"""
return self.agenda_item.pk
def get_agenda_title_information(self):
return {"title": self.title}