no update fechas YA OK
Signed-off-by: Omar Sánchez Pizarro <omar.sanchez@pistacero.net>
This commit is contained in:
@@ -125,7 +125,46 @@ class MongoDBArticleCache:
|
||||
}
|
||||
|
||||
# Preparar user_info basándose en lo que existe realmente en MongoDB
|
||||
if existing is None:
|
||||
if existing:
|
||||
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'),
|
||||
'is_favorite': existing_user_info_entry.get('is_favorite', False),
|
||||
}
|
||||
else:
|
||||
existing_user_info.append({
|
||||
'username': username,
|
||||
'worker_name': worker_name,
|
||||
'notified': True,
|
||||
'notified_at': now,
|
||||
'is_favorite': False,
|
||||
})
|
||||
|
||||
# Solo hacer update si el precio cambió
|
||||
if existing.get('price') != article.get_price():
|
||||
update_data = dict(base_fields)
|
||||
update_data['user_info'] = existing_user_info
|
||||
operations.append(
|
||||
UpdateOne(
|
||||
{'platform': platform, 'id': article_id},
|
||||
{'$set': update_data}
|
||||
)
|
||||
)
|
||||
else:
|
||||
# Artículo nuevo
|
||||
new_article_data = dict(base_fields)
|
||||
new_article_data['user_info'] = [{
|
||||
|
||||
Reference in New Issue
Block a user