From 613727321d9a993a00b84baa617bf5559a6e670d Mon Sep 17 00:00:00 2001 From: metatroncubeswdev Date: Thu, 29 Oct 2026 01:20:58 -0400 Subject: [PATCH] LinkedIn: keep company Page names on disk for 30 days Restarts and reconnects no longer spend LinkedIn's small daily lookup limit. Co-Authored-By: Claude Opus 5.5 --- connector/src/platforms/linkedin.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/connector/src/platforms/linkedin.js b/connector/src/platforms/linkedin.js index a8949d7..dc1048a 100644 --- a/connector/src/platforms/linkedin.js +++ b/connector/src/platforms/linkedin.js @@ -1,5 +1,8 @@ // LinkedIn: post to a person's profile or to a company Page they administer. // Company Pages need the Community Management API product on the LinkedIn app (approval required). +import fs from "node:fs"; +import path from "node:path"; +import { PROJECT_ROOT } from "../env.js"; import { request, bytesOf, isVideo, sizeOf } from "./http.js"; const API = "https://api.linkedin.com"; @@ -48,8 +51,11 @@ async function uploadVideo(token, owner, src) { // Company Page names. LinkedIn caps lookups per app and member per day, so names are cached for a day and // fetched in batches of 50, from organizationsLookup first and the organizations resource if that is capped. -const NAME_TTL = 24 * 3600 * 1000; -const nameCache = new Map(); +// Kept on disk so restarts don't spend the day's lookups again. +const NAME_TTL = 30 * 24 * 3600 * 1000; +const NAME_FILE = path.join(PROJECT_ROOT, "data", "linkedin-pages.json"); +const nameCache = new Map((() => { try { return Object.entries(JSON.parse(fs.readFileSync(NAME_FILE, "utf8"))); } catch { return []; } })()); +const saveNames = () => { try { fs.writeFileSync(NAME_FILE, JSON.stringify(Object.fromEntries(nameCache))); } catch { /* cache only */ } }; async function pageNames(token, ids) { const names = {}; const missing = []; @@ -71,6 +77,7 @@ async function pageNames(token, ids) { } catch { /* capped or not allowed: try the next resource, else keep ids */ } } } + if (missing.length) saveNames(); return names; }