Spaces:
Sleeping
Sleeping
Update models.py
Browse files
models.py
CHANGED
|
@@ -284,7 +284,7 @@ def add_question_to_db(theme, question, correct_option, difficulty):
|
|
| 284 |
|
| 285 |
theme_check_query = "SELECT COUNT(*) FROM themes WHERE theme = %s"
|
| 286 |
cursor.execute(theme_check_query, (theme,))
|
| 287 |
-
theme_exists = cursor.fetchone()[
|
| 288 |
|
| 289 |
if theme_exists == 0:
|
| 290 |
insert_query = "INSERT INTO themes (theme, theme_bank, theme_quiz_table) VALUES (%s, %s, %s)"
|
|
@@ -324,9 +324,9 @@ def add_question_to_db(theme, question, correct_option, difficulty):
|
|
| 324 |
"""
|
| 325 |
cursor.execute(theme_table_creation_query)
|
| 326 |
|
| 327 |
-
check_query = f"SELECT COUNT(*) FROM
|
| 328 |
cursor.execute(check_query, (question,))
|
| 329 |
-
is_duplicate = cursor.fetchone()[
|
| 330 |
|
| 331 |
if is_duplicate:
|
| 332 |
logging.warning("Duplicate question detected for theme %s: %s", safe_theme, question)
|
|
|
|
| 284 |
|
| 285 |
theme_check_query = "SELECT COUNT(*) FROM themes WHERE theme = %s"
|
| 286 |
cursor.execute(theme_check_query, (theme,))
|
| 287 |
+
theme_exists = cursor.fetchone()["COUNT(*)"]
|
| 288 |
|
| 289 |
if theme_exists == 0:
|
| 290 |
insert_query = "INSERT INTO themes (theme, theme_bank, theme_quiz_table) VALUES (%s, %s, %s)"
|
|
|
|
| 324 |
"""
|
| 325 |
cursor.execute(theme_table_creation_query)
|
| 326 |
|
| 327 |
+
check_query = f"SELECT COUNT(*) FROM `{safe_theme}_bank` WHERE question_by_llm = %s"
|
| 328 |
cursor.execute(check_query, (question,))
|
| 329 |
+
is_duplicate = cursor.fetchone()["COUNT(*)"] > 0
|
| 330 |
|
| 331 |
if is_duplicate:
|
| 332 |
logging.warning("Duplicate question detected for theme %s: %s", safe_theme, question)
|