check for existing record before inserting

This commit is contained in:
Antonio J. Delgado 2025-02-17 14:28:32 +02:00
parent 07a75b73cc
commit f5b07072ad

View file

@ -235,8 +235,16 @@ class MastodonEmailBridge:
conn.quit() conn.quit()
self._log.debug("Adding entry to database...") self._log.debug("Adding entry to database...")
cur = self.sqlite.cursor() cur = self.sqlite.cursor()
res = cur.execute("SELECT id FROM sent_items WHERE id =?", data['id'])
rows = res.fetchall()
if len(rows) == 0:
cur.execute(f"INSERT INTO sent_items (id, date) VALUES ({data['id']}, {time.time()})") cur.execute(f"INSERT INTO sent_items (id, date) VALUES ({data['id']}, {time.time()})")
self.sqlite.commit() self.sqlite.commit()
else:
self._log.warning(
"There was at least one record already with the same id %s, check if another instance of this script is running.",
data['id']
)
self.sent_items.append(data['id']) self.sent_items.append(data['id'])
return True return True