mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2025-12-09 13:06:45 +03:00
refactor: Remove unnecessary console logs from event polling and retrieval
This commit is contained in:
@@ -87,36 +87,27 @@ export async function getNewEvents({
|
|||||||
lastEventTime?: Date;
|
lastEventTime?: Date;
|
||||||
}): Promise<any[]> {
|
}): Promise<any[]> {
|
||||||
try {
|
try {
|
||||||
console.log(`Getting new events for user ${userId} in channel ${channel}`);
|
// Build the query conditions
|
||||||
if (lastEventTime) {
|
const conditions = [
|
||||||
console.log(`Looking for events after ${lastEventTime.toISOString()}`);
|
eq(events.userId, userId),
|
||||||
}
|
eq(events.channel, channel),
|
||||||
|
eq(events.read, false)
|
||||||
// Build the query
|
];
|
||||||
let query = db
|
|
||||||
.select()
|
|
||||||
.from(events)
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(events.userId, userId),
|
|
||||||
eq(events.channel, channel),
|
|
||||||
eq(events.read, false)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.orderBy(events.createdAt);
|
|
||||||
|
|
||||||
// Add time filter if provided
|
// Add time filter if provided
|
||||||
if (lastEventTime) {
|
if (lastEventTime) {
|
||||||
query = query.where(gt(events.createdAt, lastEventTime));
|
conditions.push(gt(events.createdAt, lastEventTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute the query
|
// Execute the query
|
||||||
const newEvents = await query;
|
const newEvents = await db
|
||||||
console.log(`Found ${newEvents.length} new events`);
|
.select()
|
||||||
|
.from(events)
|
||||||
|
.where(and(...conditions))
|
||||||
|
.orderBy(events.createdAt);
|
||||||
|
|
||||||
// Mark events as read
|
// Mark events as read
|
||||||
if (newEvents.length > 0) {
|
if (newEvents.length > 0) {
|
||||||
console.log(`Marking ${newEvents.length} events as read`);
|
|
||||||
await db
|
await db
|
||||||
.update(events)
|
.update(events)
|
||||||
.set({ read: true })
|
.set({ read: true })
|
||||||
@@ -149,14 +140,11 @@ export async function removeDuplicateEvents(userId?: string): Promise<{ duplicat
|
|||||||
console.log("Removing duplicate events...");
|
console.log("Removing duplicate events...");
|
||||||
|
|
||||||
// Build the base query
|
// Build the base query
|
||||||
let query = db.select().from(events);
|
const allEvents = userId
|
||||||
if (userId) {
|
? await db.select().from(events).where(eq(events.userId, userId))
|
||||||
query = query.where(eq(events.userId, userId));
|
: await db.select().from(events);
|
||||||
}
|
|
||||||
|
|
||||||
const allEvents = await query;
|
|
||||||
const duplicateIds: string[] = [];
|
const duplicateIds: string[] = [];
|
||||||
const seenKeys = new Set<string>();
|
|
||||||
|
|
||||||
// Group events by user and channel, then check for duplicates
|
// Group events by user and channel, then check for duplicates
|
||||||
const eventsByUserChannel = new Map<string, typeof allEvents>();
|
const eventsByUserChannel = new Map<string, typeof allEvents>();
|
||||||
@@ -241,7 +229,7 @@ export async function cleanupOldEvents(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
const readEventsDeleted = readResult.changes || 0;
|
const readEventsDeleted = (readResult as any).changes || 0;
|
||||||
console.log(`Deleted ${readEventsDeleted} read events`);
|
console.log(`Deleted ${readEventsDeleted} read events`);
|
||||||
|
|
||||||
// Calculate the cutoff date for unread events (default to 2x the retention period)
|
// Calculate the cutoff date for unread events (default to 2x the retention period)
|
||||||
@@ -259,7 +247,7 @@ export async function cleanupOldEvents(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
const unreadEventsDeleted = unreadResult.changes || 0;
|
const unreadEventsDeleted = (unreadResult as any).changes || 0;
|
||||||
console.log(`Deleted ${unreadEventsDeleted} unread events`);
|
console.log(`Deleted ${unreadEventsDeleted} unread events`);
|
||||||
|
|
||||||
return { readEventsDeleted, unreadEventsDeleted };
|
return { readEventsDeleted, unreadEventsDeleted };
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ export const GET: APIRoute = async ({ request }) => {
|
|||||||
if (isClosed) return;
|
if (isClosed) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log(`Polling for events for user ${userId} in channel ${channel}`);
|
|
||||||
|
|
||||||
// Get new events from SQLite
|
// Get new events from SQLite
|
||||||
const events = await getNewEvents({
|
const events = await getNewEvents({
|
||||||
userId,
|
userId,
|
||||||
@@ -43,8 +41,6 @@ export const GET: APIRoute = async ({ request }) => {
|
|||||||
lastEventTime,
|
lastEventTime,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Found ${events.length} new events`);
|
|
||||||
|
|
||||||
// Send events to client
|
// Send events to client
|
||||||
if (events.length > 0) {
|
if (events.length > 0) {
|
||||||
// Update last event time
|
// Update last event time
|
||||||
@@ -52,7 +48,6 @@ export const GET: APIRoute = async ({ request }) => {
|
|||||||
|
|
||||||
// Send each event to the client
|
// Send each event to the client
|
||||||
for (const event of events) {
|
for (const event of events) {
|
||||||
console.log(`Sending event: ${JSON.stringify(event.payload)}`);
|
|
||||||
sendMessage(`data: ${JSON.stringify(event.payload)}\n\n`);
|
sendMessage(`data: ${JSON.stringify(event.payload)}\n\n`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user