Skip to content

Commit

Permalink
Remove datastore call result locking
Browse files Browse the repository at this point in the history
  • Loading branch information
luisa-beerboom committed Jul 17, 2024
1 parent 6ab8a06 commit 78cef3f
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions openslides_backend/action/actions/motion/base_create_forwarded.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def prefetch(self, action_data: ActionData) -> None:
"is_active_in_organization_id",
"name",
"motions_default_workflow_id",
"motions_default_amendment_workflow_id",
"committee_id",
"default_group_id",
"motion_submitter_ids",
Expand Down Expand Up @@ -66,9 +67,11 @@ def prefetch(self, action_data: ActionData) -> None:
"all_origin_ids",
"derived_motion_ids",
"all_derived_motion_ids",
"amendment_ids",
],
),
]
],
lock_result=False,
)

def get_user_verbose_names(self, meeting_user_ids: list[int]) -> str | None:
Expand All @@ -77,7 +80,8 @@ def get_user_verbose_names(self, meeting_user_ids: list[int]) -> str | None:
GetManyRequest(
"meeting_user", meeting_user_ids, ["user_id", "structure_level_ids"]
)
]
],
lock_result=False,
)["meeting_user"]
user_ids = [
user_id
Expand All @@ -101,7 +105,7 @@ def get_user_verbose_names(self, meeting_user_ids: list[int]) -> str | None:
requests.append(
GetManyRequest("structure_level", structure_level_ids, ["name"])
)
user_data = self.datastore.get_many(requests)
user_data = self.datastore.get_many(requests, lock_result=False)
users = user_data["user"]
structure_levels = user_data["structure_level"]
names = []
Expand Down Expand Up @@ -144,6 +148,7 @@ def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
meeting = self.datastore.get(
fqid_from_collection_and_id("meeting", instance["meeting_id"]),
["motions_default_workflow_id", "motions_default_amendment_workflow_id"],
lock_result=False,
)
self.set_state_from_workflow(instance, meeting)
committee = self.check_for_origin_id(instance)
Expand All @@ -156,6 +161,7 @@ def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
"motion_submitter",
FilterOperator("motion_id", "=", instance["origin_id"]),
["meeting_user_id"],
lock_result=False,
).values()
)
submitters = sorted(submitters, key=lambda x: x.get("weight", 10000))
Expand All @@ -171,6 +177,7 @@ def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
text_submitter = self.datastore.get(
fqid_from_collection_and_id("motion", instance["origin_id"]),
["additional_submitter"],
lock_result=False,
).get("additional_submitter")
if text_submitter:
if instance.get("additional_submitter"):
Expand All @@ -192,6 +199,7 @@ def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
amendment_ids = self.datastore.get(
fqid_from_collection_and_id("motion", instance["origin_id"]),
["amendment_ids"],
lock_result=False,
).get("amendment_ids", [])
if self.should_forward_amendments(instance):
new_amendments = self.datastore.get_many(
Expand Down Expand Up @@ -222,7 +230,8 @@ def update_instance(self, instance: dict[str, Any]) -> dict[str, Any]:
GetManyRequest(
"motion_state", list(state_ids), ["allow_motion_forwarding"]
)
]
],
lock_result=False,
)["motion_state"]
else:
states = {}
Expand Down Expand Up @@ -273,7 +282,9 @@ def create_action_result_element(

def handle_number(self, instance: dict[str, Any]) -> dict[str, Any]:
origin = self.datastore.get(
fqid_from_collection_and_id("motion", instance["origin_id"]), ["number"]
fqid_from_collection_and_id("motion", instance["origin_id"]),
["number"],
lock_result=False,
)
if instance.pop("use_original_number", None) and (num := origin.get("number")):
number = self.get_clean_number(num, instance["meeting_id"])
Expand All @@ -295,14 +306,17 @@ def check_for_origin_id(self, instance: dict[str, Any]) -> dict[str, Any]:
meeting = self.datastore.get(
fqid_from_collection_and_id("meeting", instance["meeting_id"]),
["committee_id"],
lock_result=False,
)
forwarded_from = self.datastore.get(
fqid_from_collection_and_id("motion", instance["origin_id"]),
["meeting_id"],
lock_result=False,
)
forwarded_from_meeting = self.datastore.get(
fqid_from_collection_and_id("meeting", forwarded_from["meeting_id"]),
["committee_id"],
lock_result=False,
)
# use the forwarding user id and id later in the handle forwarding user
# code.
Expand All @@ -311,6 +325,7 @@ def check_for_origin_id(self, instance: dict[str, Any]) -> dict[str, Any]:
"committee", forwarded_from_meeting["committee_id"]
),
["id", "name", "forward_to_committee_ids"],
lock_result=False,
)
if meeting["committee_id"] not in committee.get("forward_to_committee_ids", []):
raise ActionException(
Expand Down Expand Up @@ -340,6 +355,7 @@ def set_origin_ids(self, instance: dict[str, Any]) -> None:
origin = self.datastore.get(
fqid_from_collection_and_id("motion", instance["origin_id"]),
["all_origin_ids", "meeting_id"],
lock_result=False,
)
instance["origin_meeting_id"] = origin["meeting_id"]
instance["all_origin_ids"] = origin.get("all_origin_ids", [])
Expand All @@ -349,10 +365,12 @@ def check_state_allow_forwarding(self, instance: dict[str, Any]) -> None:
origin = self.datastore.get(
fqid_from_collection_and_id(self.model.collection, instance["origin_id"]),
["state_id"],
lock_result=False,
)
state = self.datastore.get(
fqid_from_collection_and_id("motion_state", origin["state_id"]),
["allow_motion_forwarding"],
lock_result=False,
)
if not state.get("allow_motion_forwarding"):
raise ActionException("State doesn't allow to forward motion.")
Expand Down

0 comments on commit 78cef3f

Please sign in to comment.