From 9496d0dfdeccd92c8d300de6a1df983b2423a027 Mon Sep 17 00:00:00 2001 From: TPV Date: Mon, 6 Jul 2026 18:40:43 -0700 Subject: [PATCH] added updating status on upsert --- src/monitor_utils/database.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/monitor_utils/database.py b/src/monitor_utils/database.py index 66f07d6..5199667 100644 --- a/src/monitor_utils/database.py +++ b/src/monitor_utils/database.py @@ -96,20 +96,16 @@ async def add_products_to_database( document["_id"] = doc_id old_price = existing_prices.get(doc_id) new_price = document.get("currentPrice") - - price_dropped = old_price is None or ( - new_price is not None and new_price < old_price - ) - + price_changed = new_price is not None and new_price != old_price set_on_insert = {"discoveredDate": now} - if price_dropped: + if old_price is None: + set_on_insert["status"] = ProductStatus.PENDING + elif price_changed: document["status"] = ProductStatus.PENDING document["priceBeforeDrop"] = old_price - else: - set_on_insert["status"] = ProductStatus.PENDING update = {"$set": document, "$setOnInsert": set_on_insert} - if new_price is not None and new_price != old_price: + if price_changed: update["$set"][f"pastPrices.{price_key}"] = new_price ops.append(UpdateOne({"_id": doc_id}, update, upsert=True))