check for existing record before inserting
This commit is contained in:
parent
07a75b73cc
commit
f5b07072ad
1 changed files with 10 additions and 2 deletions
|
@ -235,8 +235,16 @@ class MastodonEmailBridge:
|
|||
conn.quit()
|
||||
self._log.debug("Adding entry to database...")
|
||||
cur = self.sqlite.cursor()
|
||||
cur.execute(f"INSERT INTO sent_items (id, date) VALUES ({data['id']}, {time.time()})")
|
||||
self.sqlite.commit()
|
||||
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()})")
|
||||
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'])
|
||||
return True
|
||||
|
||||
|
|
Loading…
Reference in a new issue