fix: remove dead BABY_CATEGORIES constant and emoji from logs
This commit is contained in:
@@ -4,12 +4,6 @@ import redisClient from './redis-client.js';
|
|||||||
const OFF_API_BASE = 'https://world.openfoodfacts.org/api/v2';
|
const OFF_API_BASE = 'https://world.openfoodfacts.org/api/v2';
|
||||||
const CACHE_TTL = 3600;
|
const CACHE_TTL = 3600;
|
||||||
|
|
||||||
const BABY_CATEGORIES = {
|
|
||||||
'baby food': 'baby_food',
|
|
||||||
'baby milk': 'baby_milk',
|
|
||||||
'baby cereal': 'baby_cereal',
|
|
||||||
};
|
|
||||||
|
|
||||||
export function transformOFFProduct(offProduct) {
|
export function transformOFFProduct(offProduct) {
|
||||||
if (!offProduct || !offProduct._id || !offProduct.product_name) {
|
if (!offProduct || !offProduct._id || !offProduct.product_name) {
|
||||||
return null;
|
return null;
|
||||||
@@ -54,11 +48,11 @@ export async function searchBabyProducts(query) {
|
|||||||
try {
|
try {
|
||||||
const cachedData = await redisClient.get(cacheKey);
|
const cachedData = await redisClient.get(cacheKey);
|
||||||
if (cachedData) {
|
if (cachedData) {
|
||||||
console.log(`📦 Cache hit for OFF search: ${searchTerm}`);
|
console.log(`Cache hit for OFF search: ${searchTerm}`);
|
||||||
return JSON.parse(cachedData);
|
return JSON.parse(cachedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`🌐 Fetching from OFF API: ${searchTerm}`);
|
console.log(`Fetching from OFF API: ${searchTerm}`);
|
||||||
const response = await axios.get(`${OFF_API_BASE}/search`, {
|
const response = await axios.get(`${OFF_API_BASE}/search`, {
|
||||||
params: {
|
params: {
|
||||||
categories_tags: 'baby-food',
|
categories_tags: 'baby-food',
|
||||||
@@ -76,7 +70,7 @@ export async function searchBabyProducts(query) {
|
|||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
|
|
||||||
await redisClient.setEx(cacheKey, CACHE_TTL, JSON.stringify(products));
|
await redisClient.setEx(cacheKey, CACHE_TTL, JSON.stringify(products));
|
||||||
console.log(`✅ Cached ${products.length} OFF products for: ${searchTerm}`);
|
console.log(`Cached ${products.length} OFF products for: ${searchTerm}`);
|
||||||
return products;
|
return products;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,11 +91,11 @@ export async function getBabyProductDetails(barcode) {
|
|||||||
try {
|
try {
|
||||||
const cachedData = await redisClient.get(cacheKey);
|
const cachedData = await redisClient.get(cacheKey);
|
||||||
if (cachedData) {
|
if (cachedData) {
|
||||||
console.log(`📦 Cache hit for OFF product: ${barcode}`);
|
console.log(`Cache hit for OFF product: ${barcode}`);
|
||||||
return JSON.parse(cachedData);
|
return JSON.parse(cachedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`🌐 Fetching OFF product details: ${barcode}`);
|
console.log(`Fetching OFF product details: ${barcode}`);
|
||||||
const response = await axios.get(`${OFF_API_BASE}/product/${barcode}.json`, {
|
const response = await axios.get(`${OFF_API_BASE}/product/${barcode}.json`, {
|
||||||
timeout: 5000,
|
timeout: 5000,
|
||||||
});
|
});
|
||||||
@@ -111,7 +105,7 @@ export async function getBabyProductDetails(barcode) {
|
|||||||
|
|
||||||
if (product) {
|
if (product) {
|
||||||
await redisClient.setEx(cacheKey, CACHE_TTL, JSON.stringify(product));
|
await redisClient.setEx(cacheKey, CACHE_TTL, JSON.stringify(product));
|
||||||
console.log(`✅ Cached OFF product: ${barcode}`);
|
console.log(`Cached OFF product: ${barcode}`);
|
||||||
return product;
|
return product;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,7 +122,7 @@ export async function clearCache(pattern = 'off:*') {
|
|||||||
const keys = await redisClient.keys(pattern);
|
const keys = await redisClient.keys(pattern);
|
||||||
if (keys.length > 0) {
|
if (keys.length > 0) {
|
||||||
await redisClient.del(keys);
|
await redisClient.del(keys);
|
||||||
console.log(`🗑️ Cleared ${keys.length} OFF cache entries`);
|
console.log(`Cleared ${keys.length} OFF cache entries`);
|
||||||
return keys.length;
|
return keys.length;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user