(channelId: string)
| 174 | const SYSTEM_CHANNEL_CACHE_TTL_MS = 5 * 60 * 1000; |
| 175 | |
| 176 | async function getSystemChannelRole(channelId: string): Promise<SystemChannelRole | null> { |
| 177 | if (!systemChannelMap || Date.now() > systemChannelMapExpiresAt) { |
| 178 | if (!systemChannelRefreshPromise) { |
| 179 | systemChannelRefreshPromise = (async () => { |
| 180 | const map = new Map<string, SystemChannelRole>(); |
| 181 | const [prospect, escalation, billing, error, admin] = await Promise.all([ |
| 182 | getProspectChannel(), |
| 183 | getEscalationChannel(), |
| 184 | getBillingChannel(), |
| 185 | getErrorChannel(), |
| 186 | getAdminChannel(), |
| 187 | ]); |
| 188 | if (prospect.channel_id) map.set(prospect.channel_id, 'prospect'); |
| 189 | if (escalation.channel_id) map.set(escalation.channel_id, 'escalation'); |
| 190 | if (billing.channel_id) map.set(billing.channel_id, 'billing'); |
| 191 | if (error.channel_id) map.set(error.channel_id, 'error'); |
| 192 | if (admin.channel_id) map.set(admin.channel_id, 'admin'); |
| 193 | systemChannelMap = map; |
| 194 | systemChannelMapExpiresAt = Date.now() + SYSTEM_CHANNEL_CACHE_TTL_MS; |
| 195 | systemChannelRefreshPromise = null; |
| 196 | })(); |
| 197 | } |
| 198 | await systemChannelRefreshPromise; |
| 199 | } |
| 200 | return systemChannelMap!.get(channelId) ?? null; |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Shared database instance for working group lookups |
no test coverage detected