From ba2d18418aea8dc0b44b52361ee7e11ae31a5d19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 7 Jun 2024 11:56:58 -0400 Subject: [PATCH] refactor: comment out verbose logs --- src/activitypub/actors.js | 8 ++++---- src/activitypub/helpers.js | 2 +- src/activitypub/inbox.js | 6 +++--- src/activitypub/index.js | 20 ++++++++++---------- src/activitypub/notes.js | 12 ++++++------ 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/activitypub/actors.js b/src/activitypub/actors.js index 1faaccd5b0..46f4d382e1 100644 --- a/src/activitypub/actors.js +++ b/src/activitypub/actors.js @@ -68,14 +68,14 @@ Actors.assert = async (ids, options = {}) => { return true; } - winston.verbose(`[activitypub/actors] Asserting ${ids.length} actor(s)`); + // winston.verbose(`[activitypub/actors] Asserting ${ids.length} actor(s)`); const urlMap = new Map(); const followersUrlMap = new Map(); const pubKeysMap = new Map(); let actors = await Promise.all(ids.map(async (id) => { try { - winston.verbose(`[activitypub/actors] Processing ${id}`); + // winston.verbose(`[activitypub/actors] Processing ${id}`); const actor = (typeof id === 'object' && id.hasOwnProperty('id')) ? id : await activitypub.get('uid', 0, id); // Follow counts @@ -88,7 +88,7 @@ Actors.assert = async (ids, options = {}) => { actor.followingCount = following.totalItems; } catch (e) { // no action required - winston.verbose(`[activitypub/actor.assert] Unable to retrieve follower counts for ${actor.id}`); + // winston.verbose(`[activitypub/actor.assert] Unable to retrieve follower counts for ${actor.id}`); } // Post count @@ -97,7 +97,7 @@ Actors.assert = async (ids, options = {}) => { actor.postcount = outbox.totalItems; } catch (e) { // no action required - winston.verbose(`[activitypub/actor.assert] Unable to retrieve post counts for ${actor.id}`); + // winston.verbose(`[activitypub/actor.assert] Unable to retrieve post counts for ${actor.id}`); } // Save url for backreference diff --git a/src/activitypub/helpers.js b/src/activitypub/helpers.js index 37a5fdbcc5..bc1d37f50b 100644 --- a/src/activitypub/helpers.js +++ b/src/activitypub/helpers.js @@ -102,7 +102,7 @@ Helpers.query = async (id) => { }; Helpers.generateKeys = async (type, id) => { - winston.verbose(`[activitypub] Generating RSA key-pair for ${type} ${id}`); + // winston.verbose(`[activitypub] Generating RSA key-pair for ${type} ${id}`); const { publicKey, privateKey, diff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.js index 6978e9541b..b47fdfeab7 100644 --- a/src/activitypub/inbox.js +++ b/src/activitypub/inbox.js @@ -41,7 +41,7 @@ inbox.create = async (req) => { const response = await activitypub.notes.assert(0, object); if (response) { - winston.verbose(`[activitypub/inbox] Parsing ${response.count} notes into topic ${response.tid}`); + // winston.verbose(`[activitypub/inbox] Parsing ${response.count} notes into topic ${response.tid}`); // todo: put this somewhere better if need be... maybe this is better as api.activitypub.announce.note? const cid = await topics.getTopicField(response.tid, 'cid'); @@ -153,7 +153,7 @@ inbox.delete = async (req) => { // } default: { - winston.verbose(`[activitypub/inbox.delete] Object (${object}) does not exist locally. Doing nothing.`); + // winston.verbose(`[activitypub/inbox.delete] Object (${object}) does not exist locally. Doing nothing.`); break; } } @@ -440,7 +440,7 @@ inbox.undo = async (req) => { id = id || object.object; // remote announces const exists = await posts.exists(id); if (!exists) { - winston.verbose(`[activitypub/inbox/undo] Attempted to undo announce of ${id} but couldn't find it, so doing nothing.`); + // winston.verbose(`[activitypub/inbox/undo] Attempted to undo announce of ${id} but couldn't find it, so doing nothing.`); } await activitypub.notes.announce.remove(id, actor); diff --git a/src/activitypub/index.js b/src/activitypub/index.js index 69f16a9b61..bdc3d1a687 100644 --- a/src/activitypub/index.js +++ b/src/activitypub/index.js @@ -43,7 +43,7 @@ ActivityPub.notes = require('./notes'); ActivityPub.actors = require('./actors'); ActivityPub.startJobs = () => { - winston.verbose('[activitypub/jobs] Registering jobs.'); + // winston.verbose('[activitypub/jobs] Registering jobs.'); new CronJob('0 0 * * *', ActivityPub.notes.prune, null, true, null, null, false); // change last argument to true for debugging }; @@ -165,9 +165,9 @@ ActivityPub.sign = async ({ key, keyId }, url, payload) => { }; ActivityPub.verify = async (req) => { - winston.verbose('[activitypub/verify] Starting signature verification...'); + // winston.verbose('[activitypub/verify] Starting signature verification...'); if (!req.headers.hasOwnProperty('signature')) { - winston.verbose('[activitypub/verify] Failed, no signature header.'); + // winston.verbose('[activitypub/verify] Failed, no signature header.'); return false; } @@ -215,17 +215,17 @@ ActivityPub.verify = async (req) => { // Verify the signature string via public key try { // Retrieve public key from remote instance - winston.verbose(`[activitypub/verify] Retrieving pubkey for ${keyId}`); + // winston.verbose(`[activitypub/verify] Retrieving pubkey for ${keyId}`); const { publicKeyPem } = await ActivityPub.fetchPublicKey(keyId); const verify = createVerify('sha256'); verify.update(signed_string); verify.end(); - winston.verbose('[activitypub/verify] Attempting signed string verification'); + // winston.verbose('[activitypub/verify] Attempting signed string verification'); const verified = verify.verify(publicKeyPem, signature, 'base64'); return verified; } catch (e) { - winston.verbose('[activitypub/verify] Failed, key retrieval or verification failure.'); + // winston.verbose('[activitypub/verify] Failed, key retrieval or verification failure.'); return false; } }; @@ -239,7 +239,7 @@ ActivityPub.get = async (type, id, uri) => { const keyData = await ActivityPub.getPrivateKey(type, id); const headers = id >= 0 ? await ActivityPub.sign(keyData, uri) : {}; - winston.verbose(`[activitypub/get] ${uri}`); + // winston.verbose(`[activitypub/get] ${uri}`); try { const { response, body } = await request.get(uri, { headers: { @@ -278,7 +278,7 @@ pubsub.on(`activitypub-retry-queue:lruCache:del`, (keys) => { async function sendMessage(uri, id, type, payload, attempts = 1) { const keyData = await ActivityPub.getPrivateKey(type, id); const headers = await ActivityPub.sign(keyData, uri, payload); - winston.verbose(`[activitypub/send] ${uri}`); + // winston.verbose(`[activitypub/send] ${uri}`); try { const { response, body } = await request.post(uri, { headers: { @@ -289,7 +289,7 @@ async function sendMessage(uri, id, type, payload, attempts = 1) { }); if (String(response.statusCode).startsWith('2')) { - winston.verbose(`[activitypub/send] Successfully sent ${payload.type} to ${uri}`); + // winston.verbose(`[activitypub/send] Successfully sent ${payload.type} to ${uri}`); } else { throw new Error(String(body)); } @@ -302,7 +302,7 @@ async function sendMessage(uri, id, type, payload, attempts = 1) { const timeoutId = setTimeout(() => sendMessage(uri, id, type, payload, attempts + 1), timeout); ActivityPub.retryQueue.set(queueId, timeoutId); - winston.verbose(`[activitypub/send] Added ${payload.type} to ${uri} to retry queue for ${timeout}ms`); + // winston.verbose(`[activitypub/send] Added ${payload.type} to ${uri} to retry queue for ${timeout}ms`); } else { winston.warn(`[activitypub/send] Max attempts reached for ${payload.type} to ${uri}; giving up on sending`); } diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js index 21cd7339ac..3dc2106743 100644 --- a/src/activitypub/notes.js +++ b/src/activitypub/notes.js @@ -55,7 +55,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => { members.push(await posts.exists(mainPid)); if (tid && members.every(Boolean)) { // All cached, return early. - winston.verbose('[notes/assert] No new notes to process.'); + // winston.verbose('[notes/assert] No new notes to process.'); unlock(id); return { tid, count: 0 }; } @@ -97,7 +97,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => { return post; }).filter((p, idx) => !members[idx]); const count = unprocessed.length; - winston.verbose(`[notes/assert] ${count} new note(s) found.`); + // winston.verbose(`[notes/assert] ${count} new note(s) found.`); const [ids, timestamps] = [ unprocessed.map(n => (utils.isNumber(n.pid) ? parseInt(n.pid, 10) : n.pid)), @@ -299,7 +299,7 @@ Notes.syncUserInboxes = async function (tid, uid) { const keys = Array.from(uids).map(uid => `uid:${uid}:inbox`); const score = await db.sortedSetScore(`cid:${cid}:tids`, tid); - winston.verbose(`[activitypub/syncUserInboxes] Syncing tid ${tid} with ${uids.size} inboxes`); + // winston.verbose(`[activitypub/syncUserInboxes] Syncing tid ${tid} with ${uids.size} inboxes`); await Promise.all([ db.sortedSetsAdd(keys, keys.map(() => score || Date.now()), tid), db.setAdd(`tid:${tid}:recipients`, Array.from(uids)), @@ -381,12 +381,12 @@ Notes.prune = async () => { * - Replied to (contains a local reply) * - Post within is liked */ - winston.verbose('[notes/prune] Starting scheduled pruning of topics'); + // winston.verbose('[notes/prune] Starting scheduled pruning of topics'); const start = 0; const stop = Date.now() - (1000 * 60 * 60 * 24 * 30); // 30 days; todo: make configurable? let tids = await db.getSortedSetRangeByScore('cid:-1:tids', 0, -1, start, stop); - winston.verbose(`[notes/prune] Found ${tids.length} topics older than 30 days (since last activity).`); + // winston.verbose(`[notes/prune] Found ${tids.length} topics older than 30 days (since last activity).`); const posters = await db.getSortedSetsMembers(tids.map(tid => `tid:${tid}:posters`)); const hasLocalVoter = await Promise.all(tids.map(async (tid) => { @@ -412,7 +412,7 @@ Notes.prune = async () => { return !localPoster && !localVoter; }); - winston.verbose(`[notes/prune] ${tids.length} topics eligible for pruning`); + // winston.verbose(`[notes/prune] ${tids.length} topics eligible for pruning`); await batch.processArray(tids, async (tids) => { await Promise.all(tids.map(async (tid) => {