Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/api/cron/push-scheduler/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function GET(req: Request) {
const isPushReady = initWebPush();

if (isPushReady) {
for (const push of scheduledPushes) {
await Promise.all(scheduledPushes.map(async (push: { id: string; topic: string; title: string; message: string; image_url: string }) => {
// Pobierz odbiorców dla danego tematu
let query = supabase.from('push_subscriptions').select('subscription_data');
if (push.topic !== 'wszystkie') {
Expand All @@ -55,12 +55,15 @@ export async function GET(req: Request) {
webpush.sendNotification(s.subscription_data, payload).catch(() => null)
));
}
}));

// Zmień status na wysłane
// Zmień status na wysłane
const pushIds = scheduledPushes.map((p: { id: string }) => p.id);
if (pushIds.length > 0) {
await supabase
.from('push_history')
.update({ status: 'sent', created_at: now })
.eq('id', push.id);
.in('id', pushIds);
}
} else {
console.warn('[CRON] Pominięto wysyłkę zaplanowanych powiadomień - brak konfiguracji VAPID.');
Expand Down
34 changes: 34 additions & 0 deletions test_perf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const performance = require('perf_hooks').performance;

async function mockQuery(delayMs) {
return new Promise(resolve => setTimeout(resolve, delayMs));
}

async function sequential(pushes) {
const start = performance.now();
for (const push of pushes) {
await mockQuery(50); // mock query subs
await mockQuery(50); // mock update status
}
return performance.now() - start;
}

async function optimized(pushes) {
const start = performance.now();
await Promise.all(pushes.map(async (push) => {
await mockQuery(50); // mock query subs
}));
// mock bulk update
await mockQuery(50);
return performance.now() - start;
}

async function run() {
const pushes = new Array(10).fill({});
const seqTime = await sequential(pushes);
const optTime = await optimized(pushes);
console.log(`Sequential time: ${seqTime.toFixed(2)} ms`);
console.log(`Optimized time: ${optTime.toFixed(2)} ms`);
}

run();