Skip to content

Commit 721e406

Browse files
authored
Merge pull request #11 from iNishant/feature/postgres-matrix
postgres test matrix
2 parents 5ddaba6 + f59a9aa commit 721e406

File tree

5 files changed

+35
-27
lines changed

5 files changed

+35
-27
lines changed

.github/workflows/test.yml

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,24 @@ on:
99

1010
permissions:
1111
contents: read
12-
1312
jobs:
14-
build:
15-
13+
test:
1614
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
python-version: ["3.9", "3.10", "3.11"]
18+
django-version: ["4.0", "4.1", "4.2", "5.0", "5.1"]
19+
exclude:
20+
# Django 5.0+ requires Python 3.10+
21+
- python-version: "3.9"
22+
django-version: "5.0"
23+
- python-version: "3.9"
24+
django-version: "5.1"
25+
max-parallel: 5
1726

1827
services:
1928
postgres:
20-
image: postgres
29+
image: postgres:13
2130
env:
2231
POSTGRES_PASSWORD: postgres
2332
options: >-
@@ -29,17 +38,18 @@ jobs:
2938
- 5432:5432
3039

3140
steps:
32-
- uses: actions/checkout@v3
33-
- name: Set up Python 3.9
34-
uses: actions/setup-python@v3
35-
with:
36-
python-version: "3.9"
37-
- name: Install dependencies
38-
run: |
39-
python -m pip install --upgrade pip
40-
pip install -r requirements.txt
41-
pip install -r dev-requirements.txt
42-
- name: Run tests
43-
run: |
44-
./check-lint.sh
45-
python manage.py test -v 3 --no-input
41+
- uses: actions/checkout@v3
42+
- name: Set up Python ${{ matrix.python-version }}
43+
uses: actions/setup-python@v4
44+
with:
45+
python-version: ${{ matrix.python-version }}
46+
- name: Install dependencies
47+
run: |
48+
python -m pip install --upgrade pip
49+
pip install -r requirements.txt
50+
pip install -r dev-requirements.txt
51+
pip install Django==${{ matrix.django-version }}
52+
- name: Run tests
53+
run: |
54+
./check-lint.sh
55+
python manage.py test -v 3 --no-input

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Django Querysets Single Query Fetch
22

3-
Executes multiple querysets over a single db query and returns results which would have been returned in normal evaluation of querysets. This can help in critical paths to avoid network/connection-pooler latency if db cpu/mem are nowhere near exhaustion. Ideal use case is fetching multiple small and optimised independent querysets where above mentioned latencies can dominate total execution time.
3+
Executes multiple querysets over a single db query and returns results which would have been returned in normal evaluation of querysets. This can help in critical paths to avoid network latency. Ideal use case is fetching multiple small and optimised independent querysets where above mentioned latencies can dominate total execution time.
44

55
Supports only Postgres as of now
66

@@ -45,12 +45,11 @@ Fetching count of queryset using `QuerysetCountWrapper` (since `queryset.count()
4545
from django_querysets_single_query_fetch.service import QuerysetsSingleQueryFetch, QuerysetCountWrapper
4646

4747
querysets = [QuerysetCountWrapper(queryset=queryset1), queryset2, ...]
48-
results = QuerysetsSingleQueryFetch(querysets=querysets)
48+
results = QuerysetsSingleQueryFetch(querysets=querysets)
4949

50-
assert results == [queryset1.count(), list(queryset2), ...]
50+
assert results == [queryset1.count(), list(queryset2), ...]
5151
```
5252

53-
5453
## Contribution suggestions
5554

5655
- Add tests (django version matrix, different types and parsing etc)
@@ -65,7 +64,6 @@ assert results == [queryset1.count(), list(queryset2), ...]
6564
- MySQL support as an experiment
6665
- "How it works" section/diagram?
6766

68-
6967
## Notes
7068

7169
- Note parallelisation by postgres is not guaranteed, as it depends on lot of config params (max_parallel_workers_per_gather, min_parallel_table_scan_size, max_parallel_workers etc). Even without parallelisation, this can be faster than normal one-by-one evaluation of querysets due to reduced no of network trips.

django_querysets_single_query_fetch/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def _get_fetch_count_compiler_from_queryset(
8383
slightly modified copy paste from get_count and get_aggregation in django.db.models.sql.compiler
8484
"""
8585
obj = queryset.query.clone()
86-
obj.add_annotation(Count("*"), alias="__count", is_summary=True)
86+
obj.add_annotation(Count("*"), alias="__count")
8787
added_aggregate_names = ["__count"]
8888
existing_annotations = [
8989
annotation

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
django==4
1+
django==4.2
22
psycopg2==2.9.9

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
setuptools.setup(
44
name="django_querysets_single_query_fetch",
5-
version="0.0.11",
5+
version="0.0.12",
66
description="Execute multiple Django querysets in a single SQL query",
77
long_description="Utility which executes multiple Django querysets over a single network/query call and returns results which would have been returned in normal evaluation of querysets",
88
author="Nishant Singh",
99
author_email="nishant.singh@mydukaan.io",
1010
license="Apache Software License",
1111
packages=["django_querysets_single_query_fetch"],
1212
zip_safe=False,
13-
install_requires=["django>3"],
13+
install_requires=["django>=4.0,<5.2"],
1414
python_requires=">=3.9",
1515
include_package_data=True,
1616
package_data={},

0 commit comments

Comments
 (0)