mirror of
https://github.com/elisiariocouto/leggen.git
synced 2025-12-14 02:42:21 +00:00
fix(api): Prevent duplicate notifications for existing transactions during sync.
The notification system was incorrectly sending notifications for existing transactions that were being updated during sync operations. This change modifies the transaction persistence logic to only return genuinely new transactions, preventing duplicate notifications while maintaining data integrity through INSERT OR REPLACE. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -693,7 +693,7 @@ class DatabaseService:
|
||||
|
||||
# Add the display_name column
|
||||
cursor.execute("""
|
||||
ALTER TABLE accounts
|
||||
ALTER TABLE accounts
|
||||
ADD COLUMN display_name TEXT
|
||||
""")
|
||||
|
||||
@@ -857,6 +857,14 @@ class DatabaseService:
|
||||
|
||||
for transaction in transactions:
|
||||
try:
|
||||
# Check if transaction already exists before insertion
|
||||
cursor.execute(
|
||||
"""SELECT COUNT(*) FROM transactions
|
||||
WHERE accountId = ? AND transactionId = ?""",
|
||||
(transaction["accountId"], transaction["transactionId"]),
|
||||
)
|
||||
exists = cursor.fetchone()[0] > 0
|
||||
|
||||
cursor.execute(
|
||||
insert_sql,
|
||||
(
|
||||
@@ -873,7 +881,11 @@ class DatabaseService:
|
||||
json.dumps(transaction["rawTransaction"]),
|
||||
),
|
||||
)
|
||||
new_transactions.append(transaction)
|
||||
|
||||
# Only add to new_transactions if it didn't exist before
|
||||
if not exists:
|
||||
new_transactions.append(transaction)
|
||||
|
||||
except sqlite3.IntegrityError as e:
|
||||
logger.warning(
|
||||
f"Failed to insert transaction {transaction.get('transactionId')}: {e}"
|
||||
|
||||
Reference in New Issue
Block a user