From 7ab5346198765dec8047d131159bf19d5dc62990 Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Tue, 21 Jan 2020 09:48:26 +0100 Subject: [PATCH] disable caching for reverse relations --- .../core-services/relation-manager.service.ts | 11 ++++++++++ .../search-value-selector.component.ts | 20 +++++++++++-------- .../assignment-poll-dialog.component.ts | 5 ----- ...tor_size_1.py => 0027_projector_size_1.py} | 2 +- ...tor_size_2.py => 0028_projector_size_2.py} | 2 +- ...tor_size_3.py => 0029_projector_size_3.py} | 2 +- openslides/core/models.py | 1 + openslides/utils/consumers.py | 1 - tests/integration/users/test_viewset.py | 2 +- 9 files changed, 28 insertions(+), 18 deletions(-) rename openslides/core/migrations/{0026_projector_size_1.py => 0027_projector_size_1.py} (91%) rename openslides/core/migrations/{0027_projector_size_2.py => 0028_projector_size_2.py} (96%) rename openslides/core/migrations/{0028_projector_size_3.py => 0029_projector_size_3.py} (85%) diff --git a/client/src/app/core/core-services/relation-manager.service.ts b/client/src/app/core/core-services/relation-manager.service.ts index 53e86b96b..aee102088 100644 --- a/client/src/app/core/core-services/relation-manager.service.ts +++ b/client/src/app/core/core-services/relation-manager.service.ts @@ -98,6 +98,17 @@ export class RelationManagerService { viewModel: BaseViewModel, relation: RelationDefinition ): any { + // No cache for reverse relations. + // The issue: we cannot invalidate the cache, if a new object is created (The + // following example is for a O2M foreign relation): + // There is no possibility to detect the create case: The target does not update, + // all related models does not update. The autoupdate does not provide the created- + // information. So we may check, if the relaten has changed in length every time. But + // this is the same as just resolving the relation every time it is requested. So no cache here. + if (isReverseRelationDefinition(relation)) { + return this.handleRelation(model, viewModel, relation) as BaseViewModel | BaseViewModel[]; + } + let result: any; const cacheProperty = '__' + property; diff --git a/client/src/app/shared/components/search-value-selector/search-value-selector.component.ts b/client/src/app/shared/components/search-value-selector/search-value-selector.component.ts index c746607bd..6275ebb61 100644 --- a/client/src/app/shared/components/search-value-selector/search-value-selector.component.ts +++ b/client/src/app/shared/components/search-value-selector/search-value-selector.component.ts @@ -78,14 +78,18 @@ export class SearchValueSelectorComponent extends BaseFormControlComponent { - this.selectableItems = items; - if (this.contentForm) { - this.disabled = !items || (!!items && !items.length); - } - }) - ); + if (Array.isArray(value)) { + this.selectableItems = value; + } else { + this.subscriptions.push( + value.pipe(auditTime(10)).subscribe(items => { + this.selectableItems = items; + if (this.contentForm) { + this.disabled = !items || (!!items && !items.length); + } + }) + ); + } } public searchValue: FormControl; diff --git a/client/src/app/site/assignments/components/assignment-poll-dialog/assignment-poll-dialog.component.ts b/client/src/app/site/assignments/components/assignment-poll-dialog/assignment-poll-dialog.component.ts index ead48430a..25d645230 100644 --- a/client/src/app/site/assignments/components/assignment-poll-dialog/assignment-poll-dialog.component.ts +++ b/client/src/app/site/assignments/components/assignment-poll-dialog/assignment-poll-dialog.component.ts @@ -27,11 +27,6 @@ type OptionsObject = { user_id: number; user: ViewUser }[]; styleUrls: ['./assignment-poll-dialog.component.scss'] }) export class AssignmentPollDialogComponent extends BasePollDialogComponent implements OnInit { - /** - * The actual poll data to work on - */ - public poll: AssignmentPoll; - /** * The summary values that will have fields in the dialog */ diff --git a/openslides/core/migrations/0026_projector_size_1.py b/openslides/core/migrations/0027_projector_size_1.py similarity index 91% rename from openslides/core/migrations/0026_projector_size_1.py rename to openslides/core/migrations/0027_projector_size_1.py index 07d1cec47..24eebbb4a 100644 --- a/openslides/core/migrations/0026_projector_size_1.py +++ b/openslides/core/migrations/0027_projector_size_1.py @@ -6,7 +6,7 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ("core", "0025_projector_color"), + ("core", "0026_remove_history_restricted"), ] operations = [ diff --git a/openslides/core/migrations/0027_projector_size_2.py b/openslides/core/migrations/0028_projector_size_2.py similarity index 96% rename from openslides/core/migrations/0027_projector_size_2.py rename to openslides/core/migrations/0028_projector_size_2.py index 7186e39c9..b201296cd 100644 --- a/openslides/core/migrations/0027_projector_size_2.py +++ b/openslides/core/migrations/0028_projector_size_2.py @@ -37,7 +37,7 @@ def calculate_aspect_ratios(apps, schema_editor): class Migration(migrations.Migration): dependencies = [ - ("core", "0026_projector_size_1"), + ("core", "0027_projector_size_1"), ] operations = [ diff --git a/openslides/core/migrations/0028_projector_size_3.py b/openslides/core/migrations/0029_projector_size_3.py similarity index 85% rename from openslides/core/migrations/0028_projector_size_3.py rename to openslides/core/migrations/0029_projector_size_3.py index 81b623232..570d34696 100644 --- a/openslides/core/migrations/0028_projector_size_3.py +++ b/openslides/core/migrations/0029_projector_size_3.py @@ -6,7 +6,7 @@ from django.db import migrations class Migration(migrations.Migration): dependencies = [ - ("core", "0027_projector_size_2"), + ("core", "0028_projector_size_2"), ] operations = [ diff --git a/openslides/core/models.py b/openslides/core/models.py index ae108d570..e192d3955 100644 --- a/openslides/core/models.py +++ b/openslides/core/models.py @@ -8,6 +8,7 @@ from jsonfield import JSONField from openslides.utils.autoupdate import AutoupdateElement from openslides.utils.cache import element_cache, get_element_id +from openslides.utils.locking import locking from openslides.utils.manager import BaseManager from openslides.utils.models import SET_NULL_AND_AUTOUPDATE, RESTModelMixin diff --git a/openslides/utils/consumers.py b/openslides/utils/consumers.py index 3ad1029af..1073f831d 100644 --- a/openslides/utils/consumers.py +++ b/openslides/utils/consumers.py @@ -9,7 +9,6 @@ from mypy_extensions import TypedDict from ..utils.websocket import WEBSOCKET_CHANGE_ID_TOO_HIGH from . import logging from .auth import UserDoesNotExist, async_anonymous_is_enabled -from .autoupdate import AutoupdateFormat from .cache import ChangeIdTooLowError, element_cache, split_element_id from .utils import get_worker_id from .websocket import ProtocollAsyncJsonWebsocketConsumer diff --git a/tests/integration/users/test_viewset.py b/tests/integration/users/test_viewset.py index 1a0ddb6b8..8af4588fa 100644 --- a/tests/integration/users/test_viewset.py +++ b/tests/integration/users/test_viewset.py @@ -134,7 +134,7 @@ class UserCreate(TestCase): self.assertEqual(response.status_code, status.HTTP_201_CREATED) user = User.objects.get(username="test_name_Thimoo2ho7ahreighio3") self.assertEqual(user.about_me, "

<foo>bar</foo>

") - + def test_double_username(self): for field in ("last_name", "username"): response = self.client.post(reverse("user-list"), {"username": "admin"})