[nominatim-web] Ignore insert failures



commit c77efcc5420e2a4745bb5a7c754453ceb5334290
Author: Bartłomiej Piotrowski <bpiotrowski gnome org>
Date:   Fri Apr 2 15:00:26 2021 +0200

    Ignore insert failures

 app/main.py | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/app/main.py b/app/main.py
index 4807d9e..40f1fea 100644
--- a/app/main.py
+++ b/app/main.py
@@ -78,8 +78,14 @@ def search(request: Request):
     if r.status_code == 200:
         with postgres.cursor() as cur:
             now = datetime.datetime.now()
+            sql = """
+                INSERT INTO search(key,created_at,value) VALUES (%s, %s, %s)
+                ON CONFLICT ON CONSTRAINT search_key_key
+                DO NOTHING
+                """
+
             cur.execute(
-                "INSERT INTO search(key,created_at,value) VALUES (%s, %s, %s)",
+                sql,
                 (key, now, r.text),
             )
             postgres.commit()
@@ -119,8 +125,14 @@ def reverse(request: Request):
     if r.status_code == 200:
         with postgres.cursor() as cur:
             now = datetime.datetime.now()
+            sql = """
+                INSERT INTO reverse(key,created_at,value) VALUES (%s, %s, %s)
+                ON CONFLICT ON CONSTRAINT reverse_key_key
+                DO NOTHING
+            """
+
             cur.execute(
-                "INSERT INTO reverse(key,created_at,value) VALUES (%s, %s, %s)",
+                sql,
                 (key, now, r.text),
             )
             postgres.commit()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]