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()
|
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue