Skip to content

Comments

perf: optimize unit filtering queries#373

Merged
mhieta merged 1 commit intomainfrom
seer/perf/unit-filter-optimization
Jan 26, 2026
Merged

perf: optimize unit filtering queries#373
mhieta merged 1 commit intomainfrom
seer/perf/unit-filter-optimization

Conversation

@mhieta
Copy link
Contributor

@mhieta mhieta commented Jan 26, 2026

Description

Optimize unit filtering queries by using Subquery instead of distinct()-calls.

Context

PL-214

How Has This Been Tested?

Via new unit-tests.

@mhieta mhieta requested a review from a team as a code owner January 26, 2026 09:35
@sonarqubecloud
Copy link

@azure-pipelines
Copy link

PALVELUKARTTA-API branch is deployed to platta: https://palvelukartta-api-pr373.dev.hel.ninja 🚀🚀🚀

Copy link
Contributor

@voneiden voneiden left a comment

Choose a reason for hiding this comment

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

A notable (10x) performance improvement in low load conditions in test environment can be observed:

queryset = queryset.filter(service_nodes__in=[1,2,3,4,5]).distinct()

Planning Time: 0.835 ms
Execution Time: 51.425 ms

vs

matching_unit_ids = Unit.objects.filter(service_nodes__in=[1,2,3,4,5]).values("id")
queryset = queryset.filter(id__in=Subquery(matching_unit_ids))

Planning Time: 0.444 ms
Execution Time: 5.983 ms

@mhieta mhieta merged commit 470fb17 into main Jan 26, 2026
6 checks passed
@mhieta mhieta deleted the seer/perf/unit-filter-optimization branch January 26, 2026 10:05
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.

2 participants