no update fechas
Signed-off-by: Omar Sánchez Pizarro <omar.sanchez@pistacero.net>
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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,11 +143,24 @@ class MongoDBArticleCache:
|
||||
|
||||
article_data['user_info'] = existing_user_info
|
||||
|
||||
# Upsert: actualizar
|
||||
self._articles_collection.update_one(
|
||||
{'platform': article.get_platform(), 'id': str(article.get_id())},
|
||||
{'$set': article_data}
|
||||
)
|
||||
# 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}
|
||||
)
|
||||
else:
|
||||
# Artículo nuevo, crear con user_info
|
||||
article_data['user_info'] = [user_info_entry]
|
||||
@@ -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,14 +247,28 @@ class MongoDBArticleCache:
|
||||
'is_favorite': False,
|
||||
})
|
||||
|
||||
article_data['user_info'] = existing_user_info
|
||||
|
||||
operations.append(
|
||||
UpdateOne(
|
||||
{'platform': platform, 'id': article_id},
|
||||
{'$set': article_data}
|
||||
# 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},
|
||||
{'$set': article_data}
|
||||
)
|
||||
)
|
||||
)
|
||||
else:
|
||||
# Artículo nuevo
|
||||
article_data['user_info'] = [{
|
||||
|
||||
@@ -744,29 +744,47 @@ 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);
|
||||
}
|
||||
|
||||
await articlesCollection.updateOne(
|
||||
{ platform, id },
|
||||
{
|
||||
$set: {
|
||||
...articleFields,
|
||||
user_info: existingUserInfo,
|
||||
expiresAt,
|
||||
updatedAt: new Date(),
|
||||
// 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 },
|
||||
{
|
||||
$set: {
|
||||
...articleFields,
|
||||
user_info: existingUserInfo,
|
||||
expiresAt,
|
||||
updatedAt: new Date(),
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Artículo nuevo, crear con user_info
|
||||
await articlesCollection.insertOne({
|
||||
|
||||
Reference in New Issue
Block a user