no update fechas
Signed-off-by: Omar Sánchez Pizarro <omar.sanchez@pistacero.net>
This commit is contained in:
@@ -128,66 +128,8 @@ class MongoDBArticleCache:
|
|||||||
|
|
||||||
# Preparar user_info
|
# Preparar user_info
|
||||||
existing = existing_articles.get(key)
|
existing = existing_articles.get(key)
|
||||||
if existing:
|
if existing is None:
|
||||||
# Artículo existe, actualizar user_info
|
|
||||||
existing_user_info = existing.get('user_info', [])
|
|
||||||
|
|
||||||
# Buscar si ya existe user_info para este usuario
|
|
||||||
user_info_index = None
|
|
||||||
for i, ui in enumerate(existing_user_info):
|
|
||||||
if ui.get('username') == username:
|
|
||||||
user_info_index = i
|
|
||||||
break
|
|
||||||
|
|
||||||
if user_info_index is not None:
|
|
||||||
# Actualizar user_info existente pero mantener notified_at original
|
|
||||||
existing_user_info_entry = existing_user_info[user_info_index]
|
|
||||||
existing_user_info[user_info_index] = {
|
|
||||||
'username': existing_user_info_entry.get('username'),
|
|
||||||
'worker_name': worker_name or existing_user_info_entry.get('worker_name'),
|
|
||||||
'notified': True,
|
|
||||||
'notified_at': existing_user_info_entry.get('notified_at'), # Preservar notified_at original
|
|
||||||
'is_favorite': existing_user_info_entry.get('is_favorite', False),
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
# Añadir nuevo user_info
|
|
||||||
existing_user_info.append({
|
|
||||||
'username': username,
|
|
||||||
'worker_name': worker_name,
|
|
||||||
'notified': True,
|
|
||||||
'notified_at': now,
|
|
||||||
'is_favorite': False,
|
|
||||||
})
|
|
||||||
|
|
||||||
# Solo actualizar precio si es diferente, no actualizar fechas de notificación
|
|
||||||
existing_price = existing.get('price')
|
|
||||||
new_price = article.get_price()
|
|
||||||
if existing_price == new_price:
|
|
||||||
# Si el precio es el mismo, solo actualizar user_info y eliminar notifiedAt a nivel de artículo
|
|
||||||
operations.append(
|
|
||||||
UpdateOne(
|
|
||||||
{'platform': platform, 'id': article_id},
|
|
||||||
{
|
|
||||||
'$set': {'user_info': existing_user_info},
|
|
||||||
'$unset': {'notifiedAt': '', 'notified_at': ''}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
# Precio diferente, actualizar campos del artículo + user_info
|
|
||||||
# Mantener createdAt/updatedAt originales (no se incluyen en el $set)
|
|
||||||
update_data = dict(base_fields)
|
|
||||||
update_data['user_info'] = existing_user_info
|
|
||||||
operations.append(
|
|
||||||
UpdateOne(
|
|
||||||
{'platform': platform, 'id': article_id},
|
|
||||||
{
|
|
||||||
'$set': update_data,
|
|
||||||
'$unset': {'notifiedAt': '', 'notified_at': ''}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
# Artículo nuevo
|
# Artículo nuevo
|
||||||
new_article_data = dict(base_fields)
|
new_article_data = dict(base_fields)
|
||||||
new_article_data['user_info'] = [{
|
new_article_data['user_info'] = [{
|
||||||
|
|||||||
Reference in New Issue
Block a user