no update fechas

Signed-off-by: Omar Sánchez Pizarro <omar.sanchez@pistacero.net>
This commit is contained in:
Omar Sánchez Pizarro
2026-01-20 12:04:24 +01:00
parent 38d644da1f
commit 63481b500d
3 changed files with 73 additions and 30 deletions

View File

@@ -41,7 +41,6 @@ services:
# Montar archivos de configuración y datos en ubicación predecible
- ./config.yaml:/data/config.yaml:ro
- ./logs:/data/logs:rw
# Montar el directorio raíz para acceso a archivos
- .:/data/project:ro
depends_on:
mongodb:
@@ -89,7 +88,6 @@ services:
volumes:
# Montar archivos de configuración
- ./config.yaml:/app/config.yaml:ro
# Montar directorio de logs en lugar del archivo para evitar problemas
- ./logs:/app/logs:rw
depends_on:
mongodb:

View File

@@ -129,11 +129,11 @@ class MongoDBArticleCache:
break
if user_info_index is not None:
# Actualizar user_info existente
# Actualizar user_info existente pero mantener notified_at original
existing_user_info[user_info_index].update({
'worker_name': worker_name or existing_user_info[user_info_index].get('worker_name'),
'notified': True,
'notified_at': datetime.utcnow(),
# NO actualizar notified_at, mantener el valor existente
# Mantener is_favorite existente
'is_favorite': existing_user_info[user_info_index].get('is_favorite', False),
})
@@ -143,7 +143,20 @@ class MongoDBArticleCache:
article_data['user_info'] = existing_user_info
# Upsert: actualizar
# 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, no actualizar el artículo
# Solo actualizar user_info si cambió
self._articles_collection.update_one(
{'platform': article.get_platform(), 'id': str(article.get_id())},
{'$set': {'user_info': existing_user_info}}
)
else:
# Precio diferente, actualizar artículo completo
# Mantener updatedAt para saber cuándo cambió el precio
# pero NO actualizar notified_at (ya se mantiene arriba)
self._articles_collection.update_one(
{'platform': article.get_platform(), 'id': str(article.get_id())},
{'$set': article_data}
@@ -216,11 +229,11 @@ class MongoDBArticleCache:
break
if user_info_index is not None:
# Actualizar user_info existente
# Actualizar user_info existente pero mantener notified_at original
existing_user_info[user_info_index].update({
'worker_name': worker_name or existing_user_info[user_info_index].get('worker_name'),
'notified': True,
'notified_at': now,
# NO actualizar notified_at, mantener el valor existente
# Mantener is_favorite existente
'is_favorite': existing_user_info[user_info_index].get('is_favorite', False),
})
@@ -234,8 +247,22 @@ class MongoDBArticleCache:
'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
operations.append(
UpdateOne(
{'platform': platform, 'id': article_id},
{'$set': {'user_info': existing_user_info}}
)
)
else:
# Precio diferente, actualizar artículo completo
# Mantener updatedAt para saber cuándo cambió el precio
# pero NO actualizar notified_at (ya se mantiene arriba)
article_data['user_info'] = existing_user_info
operations.append(
UpdateOne(
{'platform': platform, 'id': article_id},

View File

@@ -744,18 +744,35 @@ export async function saveArticle(articleData) {
);
if (existingUserInfoIndex >= 0) {
// Actualizar user_info existente
// Actualizar user_info existente pero mantener notified_at original
existingUserInfo[existingUserInfoIndex] = {
...existingUserInfo[existingUserInfoIndex],
worker_name: worker_name || existingUserInfo[existingUserInfoIndex].worker_name,
notified: true,
notified_at: new Date(),
// NO actualizar notified_at, mantener el valor existente
};
} else {
// Añadir nuevo user_info
existingUserInfo.push(userInfoEntry);
}
// Solo actualizar precio si es diferente, no actualizar fechas de notificación
const existingPrice = existing.price;
const newPrice = articleFields.price;
if (existingPrice === newPrice) {
// Si el precio es el mismo, solo actualizar user_info
await articlesCollection.updateOne(
{ platform, id },
{
$set: {
user_info: existingUserInfo,
}
}
);
} else {
// Precio diferente, actualizar artículo completo
// Mantener updatedAt para saber cuándo cambió el precio
// pero NO actualizar notified_at (ya se mantiene arriba)
await articlesCollection.updateOne(
{ platform, id },
{
@@ -767,6 +784,7 @@ export async function saveArticle(articleData) {
}
}
);
}
} else {
// Artículo nuevo, crear con user_info
await articlesCollection.insertOne({