This commit is contained in:
shivam 2025-03-20 09:47:52 +05:30
commit a01d1d9549
2 changed files with 12 additions and 1 deletions

View File

@ -10,6 +10,13 @@ const teamRoutes = require('./routes/team');
const app = express(); const app = express();
// Clear cache for all admin routes
app.use('/admin', (req, res, next) => {
console.log('Clearing cache for admin API hit...');
cache.store.clear();
next();
});
app.use(cors({ origin: ['http://localhost:3000', '*', 'https://your-production-domain.com'] })); app.use(cors({ origin: ['http://localhost:3000', '*', 'https://your-production-domain.com'] }));
app.use(express.json({ limit: '10kb' })); app.use(express.json({ limit: '10kb' }));
app.use(security.anonymizeIP); app.use(security.anonymizeIP);

View File

@ -39,10 +39,13 @@ exports.getTodayResults = async () => {
const today = new Date().toISOString().split('T')[0]; const today = new Date().toISOString().split('T')[0];
const cacheKey = `today:${today}`; const cacheKey = `today:${today}`;
console.log(`Cache key: ${cacheKey}`);
if (cache.has(cacheKey)) { if (cache.has(cacheKey)) {
console.log('Cache hit for today\'s results.');
return cache.get(cacheKey); return cache.get(cacheKey);
} }
console.log('Cache miss. Fetching results from the database...');
const results = await db.query(` const results = await db.query(`
SELECT t.name AS team, r.result_time, SELECT t.name AS team, r.result_time,
CASE CASE
@ -54,6 +57,7 @@ exports.getTodayResults = async () => {
WHERE DATE(r.result_time) = ? WHERE DATE(r.result_time) = ?
`, [today]); `, [today]);
console.log('Caching today\'s results...');
cache.set(cacheKey, results); cache.set(cacheKey, results);
return results; return results;
}; };
@ -76,7 +80,7 @@ exports.getMonthlyResults = async (team, month) => {
} }
const results = await db.query(` const results = await db.query(`
SELECT r.result, r.result_time, SELECT r.result_time,
CASE CASE
WHEN NOW() < r.result_time THEN '-1' WHEN NOW() < r.result_time THEN '-1'
ELSE r.result ELSE r.result