Skip to content

Commit f6cf58a

Browse files
committed
Perf currency rate
1 parent 3fbbb46 commit f6cf58a

File tree

2 files changed

+84
-42
lines changed

2 files changed

+84
-42
lines changed

.gitignore

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,2 @@
1-
*
2-
!*/
3-
4-
!.gitignore
5-
6-
!misc.py
7-
8-
!exists_perf.py
9-
!exists_issue.py
10-
!bulk_insert.py
11-
!batch_update_perf.py
12-
!dependencies.py
13-
!test_indexes.py
14-
!test_count.py
15-
!perf_httpapocalypse.py
16-
!test_website_perf.py
17-
!psql_log.md
18-
!exists_smarty.py
19-
!modified_trigger_perf.py
20-
!new_domain_object.py
21-
!regex_name_get.py
22-
!__init__.py
23-
24-
!psql_exists_in_join/*.py
25-
!memory_shared_lru/*.py
26-
!memory_shared_lru/*.md
27-
!not_in_selection/*.py
28-
!not_in_selection/*.log
29-
!new_read_group/*.py
30-
!perf_unity/*.py
31-
!new_read_group/*.txt
32-
!expression_tests.sql
33-
!aggregate_perf.py
34-
!test_ormcache_sequence.py
35-
!python_issue.py
36-
!expression_performance/**/*.py
37-
!expression_performance/**/*.csv
38-
39-
!read_group_replacement.py
40-
!find_related.py
41-
!script_to_test_api.py
42-
!fake_data.py
1+
*.log
2+
**/__pycache__

perf_currency_rate.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import random
2+
import datetime
3+
4+
from itertools import product, cycle
5+
6+
from faker import Faker
7+
8+
fake = Faker()
9+
10+
# faker -r=1000 -s=',' name email ean8 vat
11+
12+
currencies_ids = list(range(1, 8))
13+
company_ids = list(range(1, 10))
14+
15+
iter_currencies_company = cycle(product(currencies_ids, company_ids))
16+
17+
today = datetime.date.today()
18+
19+
# TODO
20+
21+
with open("currency_rate.csv", "wt") as f:
22+
for i in range(100_000):
23+
24+
currency_id = next(currency_iter)
25+
26+
date
27+
28+
line = ",".join([currency_id, date, company_id])
29+
f.write(f"{line}\n")
30+
31+
32+
"""
33+
34+
SELECT DISTINCT ON ("res_currency_rate"."currency_id")
35+
"res_currency_rate"."currency_id", "res_currency_rate"."rate"
36+
FROM "res_currency_rate"
37+
WHERE "res_currency_rate"."company_id" IS NULL OR "res_currency_rate"."company_id" = 1
38+
ORDER BY
39+
"res_currency_rate"."currency_id",
40+
"res_currency_rate"."company_id",
41+
CASE WHEN "res_currency_rate"."name" <= '2025-09-02'::date THEN "res_currency_rate"."name" END DESC,
42+
CASE WHEN "res_currency_rate"."name" > '2025-09-02'::date THEN "res_currency_rate"."name" END ASC
43+
44+
SELECT
45+
"res_currency"."id",
46+
COALESCE(
47+
(
48+
SELECT "res_currency_rate"."rate"
49+
FROM "res_currency_rate"
50+
WHERE
51+
(
52+
("res_currency_rate"."company_id" IN (1) OR "res_currency_rate"."company_id" IS NULL)
53+
AND "res_currency_rate"."name" <= '2025-09-02'::date
54+
)
55+
AND "res_currency_rate"."currency_id" = "res_currency"."id"
56+
ORDER BY
57+
"res_currency_rate"."company_id",
58+
"res_currency_rate"."name" DESC
59+
LIMIT
60+
1
61+
), (
62+
SELECT
63+
"res_currency_rate"."rate"
64+
FROM
65+
"res_currency_rate"
66+
WHERE
67+
(
68+
"res_currency_rate"."company_id" IN (1)
69+
OR "res_currency_rate"."company_id" IS NULL
70+
)
71+
AND "res_currency_rate"."currency_id" = "res_currency"."id"
72+
ORDER BY
73+
"res_currency_rate"."company_id",
74+
"res_currency_rate"."name" ASC
75+
LIMIT
76+
1
77+
), 1.0
78+
)
79+
FROM
80+
"res_currency"
81+
WHERE "res_currency" = 10
82+
"""

0 commit comments

Comments
 (0)