Skip to content

Draft: Optimize project condition resolution - #1748

Closed
MyPyDavid wants to merge 3 commits into
2.5.2/fix/optimize-project-navigationfrom
2.5.2/fix/optimize-project-condition-resolution
Closed

MyPyDavid wants to merge 3 commits into
2.5.2/fix/optimize-project-navigationfrom
2.5.2/fix/optimize-project-condition-resolution

Conversation

@MyPyDavid

@MyPyDavid MyPyDavid commented Sep 2, 2026 •

Copy link
Copy Markdown
Member
  • use the new Django field_id getter instead of field.id
  • add a .for_condition_resolution(self) method to the ValueQuerySet
  • use and re-use a values_by_attribute dict of lists for the resolve action

Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
@MyPyDavid MyPyDavid self-assigned this Sep 2, 2026
@MyPyDavid MyPyDavid closed this Sep 2, 2026
@MyPyDavid MyPyDavid reopened this Sep 2, 2026
@coveralls

coveralls commented Sep 2, 2026 •

Copy link
Copy Markdown

Coverage Status

Coverage is 95.181% — 2.5.2/fix/optimize-project-condition-resolution into 2.5.2/fix/optimize-project-navigation. No base build found for 2.5.2/fix/optimize-project-navigation.

Comment thread rdmo/projects/viewsets.py Outdated
# get all values of the project
values = project.values.filter(snapshot=None).select_related('attribute', 'option')
if conditions:
values = project.values.filter(snapshot=None).for_condition_resolution()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe better just without the ..select_related('attribute', 'option') and without the .for_condition_resolution()

Comment thread rdmo/projects/viewsets.py

element_conditions = [conditions[condition_id] for condition_id in elements[element_type][element_id]]
params['result'] = check_conditions(element_conditions, values, set_prefix, set_index)
element_condition_ids = elements[element_type][element_id]

@MyPyDavid MyPyDavid Sep 3, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also have already:

          'attribute_map': (
                Attribute.objects.get_queryset_ancestors(
                    Attribute.objects.filter(id__in=attribute_ids),
                    include_self=True
                ).in_bulk()

from django.db.models.query.QuerySet.in_bulk

Comment thread rdmo/projects/utils.py Outdated


def check_conditions(conditions, values, set_prefix=None, set_index=None):
def compute_values_by_attribute(values):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, the in_bulk does not work here because we want to get many Values per single Attribute:

attribute_id 10
    → Value(id=101, set_index=0)
    → Value(id=102, set_index=1)
    → Value(id=103, collection_index=1)
    ```

Comment thread rdmo/projects/viewsets.py Outdated

values = self.get_object().values.filter(snapshot_id=snapshot_id).select_related('attribute', 'option')
values = self.get_object().values.filter(snapshot_id=snapshot_id).for_condition_resolution()
values_by_attribute = compute_values_by_attribute(values)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attribute_map

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no0o0o, attribute_values_map 😵

Comment thread rdmo/projects/viewsets.py Outdated
values = project.values.filter(snapshot=None).select_related('attribute', 'option')
if conditions:
values = project.values.filter(snapshot=None).for_condition_resolution()
values_by_attribute = compute_values_by_attribute(values)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in_bulk

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attribute_map

Comment thread rdmo/projects/viewsets.py Outdated
# get all values of the project
values = project.values.filter(snapshot=None).select_related('attribute', 'option')
if conditions:
values = project.values.filter(snapshot=None).for_condition_resolution()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just without select_releated?

Comment thread rdmo/projects/viewsets.py Outdated
element_conditions = [conditions[condition_id] for condition_id in elements[element_type][element_id]]
params['result'] = check_conditions(element_conditions, values, set_prefix, set_index)
element_condition_ids = elements[element_type][element_id]
cache_key = (tuple(sorted(element_condition_ids)), set_prefix, set_index)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should try to re-use AnswerTree for checking/resolve the conditions in here. It is better when we define this duplicated logic in one-place and maybe we could then move the resolved AnserTree in a real cache for User request to make it 2x as fast!

Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
Signed-off-by: David Wallace <david.wallace@tu-darmstadt.de>
@MyPyDavid
MyPyDavid removed this pull request from stack #1750 September 18, 2026 11:58
@MyPyDavid

Copy link
Copy Markdown
Member Author

unstacked and closed in favour of #1752

@MyPyDavid MyPyDavid closed this Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants