Merge pull request #4352 from omnivore-app/reduce-logs

reduce logs
This commit is contained in:
Hongbo Wu
2024-08-29 21:23:14 +08:00
committed by GitHub
17 changed files with 2 additions and 107 deletions

View File

@ -289,7 +289,6 @@ export const triggerRule = async (jobData: TriggerRuleJobData) => {
// get rules by calling api
const rules = await findEnabledRules(userId, ruleEventType)
if (rules.length === 0) {
console.log('No rules found')
return false
}

View File

@ -362,26 +362,6 @@ const main = async () => {
await setupCronJobs()
const queueEvents = new QueueEvents(BACKEND_QUEUE_NAME, {
connection: workerRedisClient,
})
queueEvents.on('added', async (job) => {
console.log('added job: ', job.jobId, job.name)
})
queueEvents.on('removed', async (job) => {
console.log('removed job: ', job.jobId)
})
queueEvents.on('completed', async (job) => {
console.log('completed job: ', job.jobId)
})
queueEvents.on('failed', async (job) => {
console.log('failed job: ', job.jobId)
})
workerRedisClient.on('error', (error) => {
console.trace('[queue-processor]: redis worker error', { error })
})

View File

@ -318,13 +318,6 @@ export const createArticleResolver = authorized<
savedAt,
})
log.info('New article saving', {
parsedArticle: Object.assign({}, libraryItemToSave, {
readableContent: undefined,
originalContent: undefined,
}),
})
if (uploadFileId) {
const uploadFileData = await setFileUploadComplete(uploadFileId)
if (!uploadFileData || !uploadFileData.id || !uploadFileData.fileName) {
@ -461,12 +454,6 @@ export const setBookmarkArticleResolver = authorized<
},
})
log.info('Article unbookmarked', {
item: Object.assign({}, deletedLibraryItem, {
readableContent: undefined,
originalContent: undefined,
}),
})
// Make sure article.id instead of userArticle.id has passed. We use it for cache updates
return {
bookmarkedArticle: deletedLibraryItem,

View File

@ -206,8 +206,6 @@ export const userDigestEligible = async (uid: string): Promise<boolean> => {
const featuresCacheKey = (userId: string) => `cache:features:${userId}`
export const getFeaturesCache = async (userId: string) => {
logger.debug('getFeaturesCache', { userId })
const cachedFeatures = await redisDataSource.redisClient?.get(
featuresCacheKey(userId)
)
@ -221,8 +219,6 @@ export const getFeaturesCache = async (userId: string) => {
export const setFeaturesCache = async (userId: string, features: Feature[]) => {
const value = JSON.stringify(features)
logger.debug('setFeaturesCache', { userId, value })
return redisDataSource.redisClient?.set(
featuresCacheKey(userId),
value,

View File

@ -1749,11 +1749,6 @@ const totalCountCacheKey = (userId: string, args: SearchArgs) => {
}
export const getCachedTotalCount = async (userId: string, args: SearchArgs) => {
logger.debug('Getting cached total count:', {
userId,
args,
})
const cacheKey = totalCountCacheKey(userId, args)
const cachedCount = await redisDataSource.redisClient?.get(cacheKey)
if (!cachedCount) {
@ -1770,11 +1765,6 @@ export const setCachedTotalCount = async (
) => {
const cacheKey = totalCountCacheKey(userId, args)
logger.debug('Setting cached total count:', {
cacheKey,
count,
})
await redisDataSource.redisClient?.set(cacheKey, count, 'EX', 600)
}
@ -1785,10 +1775,5 @@ export const deleteCachedTotalCount = async (userId: string) => {
return
}
logger.debug('Deleting keys:', {
keys,
userId,
})
await redisDataSource.redisClient?.del(keys)
}

View File

@ -161,8 +161,6 @@ export const findUserAndPersonalization = async (id: string) => {
const userCacheKey = (id: string) => `cache:user:${id}`
export const getCachedUser = async (id: string) => {
logger.debug(`Getting user from cache: ${id}`)
const user = await redisDataSource.redisClient?.get(userCacheKey(id))
if (!user) {
return undefined
@ -172,8 +170,6 @@ export const getCachedUser = async (id: string) => {
}
export const cacheUser = async (user: User) => {
logger.debug(`Caching user: ${user.id}`)
await redisDataSource.redisClient?.set(
userCacheKey(user.id),
JSON.stringify(user),

View File

@ -177,8 +177,6 @@ const userDefaultShortcuts = async (userId: string): Promise<Shortcut[]> => {
const shortcutsCacheKey = (userId: string) => `cache:shortcuts:${userId}`
export const getShortcutsCache = async (userId: string) => {
logger.debug(`Getting shortcuts from cache: ${userId}`)
const cachedShortcuts = await redisDataSource.redisClient?.get(
shortcutsCacheKey(userId)
)
@ -189,8 +187,6 @@ export const getShortcutsCache = async (userId: string) => {
}
export const cacheShortcuts = async (userId: string, shortcuts: Shortcut[]) => {
logger.debug(`Caching shortcuts: ${userId}`)
await redisDataSource.redisClient?.set(
shortcutsCacheKey(userId),
JSON.stringify(shortcuts),

View File

@ -33,7 +33,6 @@ export const apiLimiter = rateLimit({
const claims = await getClaimsByToken(token)
return claims ? 60 : 15
} catch (e) {
console.log('non-authenticated request')
return 15
}
},
@ -53,7 +52,6 @@ export const apiHourLimiter = rateLimit({
const claims = await getClaimsByToken(token)
return claims ? 600 : 150
} catch (e) {
console.log('non-authenticated request')
return 150
}
},

View File

@ -31,8 +31,6 @@ class PostHogClient implements AnalyticClient {
return
}
console.log('analytics', { userIds, result, properties })
}
}

View File

@ -299,12 +299,7 @@ export const processFetchContentJob = async (
}
if (fetchResult.content && !NO_CACHE_URLS.includes(url)) {
const cacheResult = await cacheFetchResult(
redisDataSource,
key,
fetchResult
)
console.log('cache result', cacheResult)
await cacheFetchResult(redisDataSource, key, fetchResult)
}
}

View File

@ -1,5 +1,5 @@
import { RedisDataSource } from '@omnivore/utils'
import { Job, Queue, QueueEvents, RedisClient, Worker } from 'bullmq'
import { Job, Queue, RedisClient, Worker } from 'bullmq'
import { JobData, processFetchContentJob } from './request_handler'
export const QUEUE = 'omnivore-content-fetch-queue'
@ -53,25 +53,5 @@ export const createWorker = (
console.error('worker error:', err)
})
const queueEvents = new QueueEvents(queueName, {
connection: redisDataSource.queueRedisClient,
})
queueEvents.on('added', (job) => {
console.log('added job:', job.jobId, job.name)
})
queueEvents.on('removed', (job) => {
console.log('removed job:', job.jobId)
})
queueEvents.on('completed', (job) => {
console.log('completed job:', job.jobId)
})
queueEvents.on('failed', (job) => {
console.log('failed job:', job.jobId)
})
return worker
}

View File

@ -159,8 +159,6 @@ export abstract class ContentHandler {
html,
headers,
}: NewsletterInput): Promise<NewsletterResult> {
console.log('handleNewsletter', from, to, subject, headers)
if (!from || !html || !subject || !to) {
console.log('invalid newsletter email')
throw new Error('invalid newsletter email')

View File

@ -13,8 +13,6 @@ const parseLabels = (labels: string): string[] => {
// labels follows format: "[""label1"",""label2""]"
return JSON.parse(labels) as string[]
} catch (error) {
console.debug('invalid labels format', labels)
// labels follows format: "[label1,label2]"
return labels
.slice(1, -1)

View File

@ -55,10 +55,8 @@ export const inboundEmailHandler = Sentry.GCPFunction.wrapHttpFunction(
console.log('no data or name for ', part)
}
}
console.log('parsed', parsed)
const headers = parseHeaders(parsed.headers)
console.log('headers', headers)
// original sender email address
const from = parsed['from']

View File

@ -45,7 +45,6 @@ const getDocumentUrl = async (
const [url] = await file.getSignedUrl(options)
return new URL(url)
} catch (e) {
console.debug('error getting signed url', e)
return undefined
}
}
@ -101,8 +100,6 @@ export const pdfHandler = Sentry.GCPFunction.wrapHttpFunction(
return res.send('ok')
}
console.log('handling pdf data', data)
let content,
title,
author,

View File

@ -214,7 +214,6 @@ export const textToSpeechHandler = Sentry.GCPFunction.wrapHttpFunction(
export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction(
async (req, res) => {
console.log('Text to speech steaming request body:', req.body)
if (!process.env.JWT_SECRET) {
console.error('JWT_SECRET not exists')
return res.status(500).send({ errorCodes: 'JWT_SECRET_NOT_EXISTS' })
@ -314,7 +313,6 @@ export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction(
// check if audio file already exists
const [exists] = await audioFile.exists()
if (exists) {
console.debug('Audio file already exists')
;[audioData] = await audioFile.download()
const [speechMarksExists] = await speechMarksFile.exists()
if (speechMarksExists) {
@ -341,7 +339,6 @@ export const textToSpeechStreamingHandler = Sentry.GCPFunction.wrapHttpFunction(
})
}
console.debug('saving audio file')
// upload audio data to GCS
await audioFile.save(audioData)
// upload speech marks to GCS

View File

@ -290,7 +290,6 @@ export const thumbnailHandler = Sentry.GCPFunction.wrapHttpFunction(
const token = req.headers.cookie?.split('auth=')[1]
if (!token) {
console.debug('no token')
return res.status(401).send('UNAUTHORIZED')
}
let uid = ''
@ -300,12 +299,10 @@ export const thumbnailHandler = Sentry.GCPFunction.wrapHttpFunction(
}
uid = decoded.uid
} catch (e) {
console.debug(e)
return res.status(401).send('UNAUTHORIZED')
}
if (!isThumbnailRequest(req.body)) {
console.debug('bad request')
return res.status(400).send('BAD_REQUEST')
}