File tree Expand file tree Collapse file tree 5 files changed +112
-1
lines changed Expand file tree Collapse file tree 5 files changed +112
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,18 @@ Changelog
6
6
7
7
.. rst-class :: emphasize-children
8
8
9
+ 0.25
10
+ ====
11
+
12
+ 0.25.0 (unreleased)
13
+ ------
14
+ Fixed
15
+ ^^^^^
16
+
17
+ Changed
18
+ ^^^^^^^
19
+ - add benchmarks for `get_for_dialect ` (#1862)
20
+
9
21
0.24
10
22
====
11
23
Original file line number Diff line number Diff line change 6
6
7
7
import pytest
8
8
9
- from tests .testmodels import BenchmarkFewFields , BenchmarkManyFields
9
+ from tests .testmodels import (
10
+ BenchmarkFewFields ,
11
+ BenchmarkManyFields ,
12
+ Tournament ,
13
+ Event ,
14
+ Team ,
15
+ DecimalFields ,
16
+ )
10
17
from tortoise .contrib .test import _restore_default , truncate_all_models
11
18
12
19
@@ -87,3 +94,22 @@ def _gen():
87
94
}
88
95
89
96
return _gen
97
+
98
+
99
+ @pytest .fixture
100
+ def create_team_with_participants () -> None :
101
+ async def _create () -> None :
102
+ tournament = await Tournament .create (name = "New Tournament" )
103
+ event = await Event .create (name = "Test" , tournament_id = tournament .id )
104
+ team = await Team .create (name = "Some Team" )
105
+ await event .participants .add (team )
106
+
107
+ asyncio .get_event_loop ().run_until_complete (_create ())
108
+
109
+
110
+ @pytest .fixture
111
+ def create_decimals () -> None :
112
+ async def _create () -> None :
113
+ await DecimalFields .create (decimal = Decimal ("1.23456" ), decimal_nodec = 18.7 )
114
+
115
+ asyncio .get_event_loop ().run_until_complete (_create ())
Original file line number Diff line number Diff line change
1
+ import asyncio
2
+
3
+ from tests .testmodels import BenchmarkFewFields , DecimalFields
4
+ from tortoise .expressions import F
5
+ from tortoise .functions import Count
6
+
7
+
8
+ def test_expressions_count (benchmark , few_fields_benchmark_dataset ):
9
+ loop = asyncio .get_event_loop ()
10
+
11
+ @benchmark
12
+ def bench ():
13
+ async def _bench ():
14
+ await BenchmarkFewFields .annotate (text_count = Count ("text" ))
15
+
16
+ loop .run_until_complete (_bench ())
17
+
18
+
19
+ def test_expressions_f (benchmark , create_decimals ):
20
+ loop = asyncio .get_event_loop ()
21
+
22
+ @benchmark
23
+ def bench ():
24
+ async def _bench ():
25
+ await DecimalFields .annotate (d = F ("decimal" )).all ()
26
+
27
+ loop .run_until_complete (_bench ())
Original file line number Diff line number Diff line change
1
+ from tortoise .fields import Field
2
+
3
+
4
+ class MyField (Field ):
5
+ @property
6
+ def MY_PROPERTY (self ):
7
+ return f"hi from { self .__class__ .__name__ } !"
8
+
9
+ OTHER_PROPERTY = "something else"
10
+
11
+ class _db_property :
12
+ def __init__ (self , field : "Field" ):
13
+ self .field = field
14
+
15
+ @property
16
+ def MY_PROPERTY (self ):
17
+ return f"hi from { self .__class__ .__name__ } of { self .field .__class__ .__name__ } !"
18
+
19
+ class _db_cls_attribute :
20
+ MY_PROPERTY = "cls_attribute"
21
+
22
+
23
+ def test_field_attribute_lookup_get_for_dialect (benchmark ):
24
+ field = MyField ()
25
+
26
+ @benchmark
27
+ def bench ():
28
+ field .get_for_dialect ("property" , "MY_PROPERTY" )
29
+ field .get_for_dialect ("postgres" , "MY_PROPERTY" )
30
+ field .get_for_dialect ("cls_attribute" , "MY_PROPERTY" )
31
+ field .get_for_dialect ("property" , "OTHER_PROPERTY" )
32
+ field .get_for_dialect ("property" , "MY_PROPERTY" )
Original file line number Diff line number Diff line change
1
+ import asyncio
2
+
3
+ from tests .testmodels import Event
4
+
5
+
6
+ def test_relations_values_related_m2m (benchmark , create_team_with_participants ):
7
+ loop = asyncio .get_event_loop ()
8
+
9
+ @benchmark
10
+ def bench ():
11
+ async def _bench ():
12
+ await Event .all ().values ("participants__name" )
13
+
14
+ loop .run_until_complete (_bench ())
You can’t perform that action at this time.
0 commit comments