Skip to content

Commit fd3ad98

Browse files
committed
[IMP] util/pg: deduplicate "{parallel_filter}"
As usual, it reduces chances of stupid mistakes (e.g. typos).
1 parent e800de2 commit fd3ad98

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/util/pg.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
ON_DELETE_ACTIONS = frozenset(("SET NULL", "CASCADE", "RESTRICT", "NO ACTION", "SET DEFAULT"))
4747
MAX_BUCKETS = int(os.getenv("MAX_BUCKETS", "150000"))
48+
PARALLEL_FILTER = "{parallel_filter}"
4849

4950

5051
class PGRegexp(str):
@@ -252,9 +253,9 @@ def explode_query_range(cr, query, table, alias=None, bucket_size=10000, prefix=
252253

253254
alias = alias or table
254255

255-
if "{parallel_filter}" not in query:
256+
if PARALLEL_FILTER not in query:
256257
sep_kw = " AND " if re.search(r"\sWHERE\s", query, re.M | re.I) else " WHERE "
257-
query += sep_kw + "{parallel_filter}"
258+
query += sep_kw + PARALLEL_FILTER
258259

259260
cr.execute(format_query(cr, "SELECT min(id), max(id) FROM {}", table))
260261
min_id, max_id = cr.fetchone()
@@ -297,10 +298,10 @@ def explode_query_range(cr, query, table, alias=None, bucket_size=10000, prefix=
297298
# Still, since the query may only be valid if there is no split, we force the usage of `prefix` in the query to
298299
# validate its correctness and avoid scripts that pass the CI but fail in production.
299300
parallel_filter = "{alias}.id IS NOT NULL".format(alias=alias)
300-
return [query.replace("{parallel_filter}", parallel_filter)]
301+
return [query.replace(PARALLEL_FILTER, parallel_filter)]
301302

302303
parallel_filter = "{alias}.id BETWEEN %(lower-bound)s AND %(upper-bound)s".format(alias=alias)
303-
query = query.replace("%", "%%").replace("{parallel_filter}", parallel_filter)
304+
query = query.replace("%", "%%").replace(PARALLEL_FILTER, parallel_filter)
304305
return [
305306
cr.mogrify(query, {"lower-bound": ids[i], "upper-bound": ids[i + 1] - 1}).decode() for i in range(len(ids) - 1)
306307
]

0 commit comments

Comments
 (0)