Skip to content
Snippets Groups Projects
Verified Commit fa62b657 authored by Eunhak Lee's avatar Eunhak Lee
Browse files

chore: enahnce logging

parent 07425dc5
No related branches found
No related tags found
No related merge requests found
Pipeline #10973 passed
......@@ -44,7 +44,9 @@ def check_similarity(_conn, name, part_type):
where_clause = "WHERE type = '{}'".format(part_type.upper()) if part_type else ""
_auto_threshold = 1.0 if part_type in ('RAM', 'SSD', 'HDD',) else 0.5
_cursor.execute("WITH comp AS (SELECT id, name, similarity(name::text, %s::text) as sim FROM parts " + where_clause + ") SELECT * FROM comp WHERE sim >=%s ORDER BY sim DESC LIMIT 5;", (name, _auto_threshold,))
sql = _cursor.mogrify("WITH comp AS (SELECT id, name, similarity(name::text, %s::text) as sim FROM parts " + where_clause + ") SELECT * FROM comp WHERE sim >=%s ORDER BY sim DESC LIMIT 5;", (name, _auto_threshold,))
logger.debug(sql)
_cursor.execute(sql)
data = _cursor.fetchall()
return data[:1] if data else None
......@@ -86,7 +88,9 @@ def create_new_one(_dict, part_type, _cursor):
INSERT INTO part_info_{type} (part_id, {columns})
(SELECT rows.id, {value_entries} FROM rows)
RETURNING part_id;""".format(type=_part_type_enum, columns=columns, value_entries=", ".join(["%s"] * len(values)))
_cursor.execute(sql, (name, _part_type_enum, "/static/img/placeholder/{}.png".format(part_type.lower()), *values))
sql = _cursor.mogrify(sql, (name, _part_type_enum, "/static/img/placeholder/{}.png".format(part_type.lower()), *values))
logger.debug(sql)
_cursor.execute(sql)
data = _cursor.fetchall()
if data:
......@@ -98,7 +102,9 @@ def check_if_parts_exist(_cursor, _user_id, _part_ids):
sql = """WITH result AS (SELECT combinations.id AS combination_id,
ARRAY(SELECT part_id FROM relations WHERE relations.combination_id = combinations.id ORDER BY relations.part_id) AS parts
FROM combinations WHERE combinations.owner_id = %s) SELECT combination_id FROM result WHERE parts = %s;"""
_cursor.execute(sql, (_user_id, _part_ids))
sql = _cursor.mogrify(sql, (_user_id, _part_ids))
logger.debug(sql)
_cursor.execute(sql)
data = _cursor.fetchall()
if not data:
......@@ -113,7 +119,9 @@ def create_combination(_cursor, nickname, _user_id):
if nickname:
_pc_name = "" + str(nickname) + "의 PC"
_cursor.execute("INSERT INTO combinations (owner_id, name) VALUES (%s, %s) RETURNING id;", (_user_id, _pc_name,))
sql = _cursor.mogrify("INSERT INTO combinations (owner_id, name) VALUES (%s, %s) RETURNING id;", (_user_id, _pc_name,))
logger.debug(sql)
_cursor.execute(sql)
data = _cursor.fetchall()
if data:
......@@ -128,7 +136,9 @@ def wire_part_to_combination(_cursor, _combination_id, *_part_ids):
values.append(_combination_id)
values.append(_part_id)
_cursor.execute("INSERT INTO relations (combination_id, part_id) VALUES " + ", ".join(["(%s, %s)" for _ in _part_ids]) + "RETURNING id, part_id", values)
sql = _cursor.mogrify("INSERT INTO relations (combination_id, part_id) VALUES " + ", ".join(["(%s, %s)" for _ in _part_ids]) + "RETURNING id, part_id", values)
logger.debug(sql)
_cursor.execute(sql)
return _cursor.fetchall()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment