diff options
author | 2023-07-08 16:23:45 +0200 | |
---|---|---|
committer | 2023-07-08 16:23:45 +0200 | |
commit | 490b4c410add19fb7af5ccfc491258c489eab93b (patch) | |
tree | ee4c7bad916d61184a493708265bafb62876dbe6 /source/features/github-actions-indicators.tsx | |
parent | 567a90067a4d7ad77e463bf4dfd6ffef785cf58f (diff) | |
download | refined-github-490b4c410add19fb7af5ccfc491258c489eab93b.tar.gz refined-github-490b4c410add19fb7af5ccfc491258c489eab93b.tar.zst refined-github-490b4c410add19fb7af5ccfc491258c489eab93b.zip |
Use new cache API (#6733)
Diffstat (limited to 'source/features/github-actions-indicators.tsx')
-rw-r--r-- | source/features/github-actions-indicators.tsx | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/source/features/github-actions-indicators.tsx b/source/features/github-actions-indicators.tsx index 7d2ffe8f..f90b7a70 100644 --- a/source/features/github-actions-indicators.tsx +++ b/source/features/github-actions-indicators.tsx @@ -1,4 +1,4 @@ -import cache from 'webext-storage-cache'; +import {CachedFunction} from 'webext-storage-cache'; import React from 'dom-chef'; import select from 'select-dom'; import {StopIcon, PlayIcon} from '@primer/octicons-react'; @@ -72,30 +72,31 @@ async function getFilesInWorkflowPath(): Promise<Record<string, string>> { return result; } -const getWorkflowsDetails = cache.function('workflows-details', async (): Promise<Record<string, Workflow & WorkflowDetails>> => { - const [workflows, workflowFiles] = await Promise.all([getWorkflows(), getFilesInWorkflowPath()]); +const workflowDetails = new CachedFunction('workflows-details', { + async updater(): Promise<Record<string, Workflow & WorkflowDetails>> { + const [workflows, workflowFiles] = await Promise.all([getWorkflows(), getFilesInWorkflowPath()]); - const details: Record<string, Workflow & WorkflowDetails> = {}; + const details: Record<string, Workflow & WorkflowDetails> = {}; - for (const workflow of workflows) { - const workflowYaml = workflowFiles[workflow.name]; + for (const workflow of workflows) { + const workflowYaml = workflowFiles[workflow.name]; - if (workflowYaml === undefined) { + if (workflowYaml === undefined) { // Cannot find workflow yaml; workflow removed. - continue; - } + continue; + } - const cron = /schedule[:\s-]+cron[:\s'"]+([^'"\n]+)/m.exec(workflowYaml); + const cron = /schedule[:\s-]+cron[:\s'"]+([^'"\n]+)/m.exec(workflowYaml); - details[workflow.name] = { - ...workflow, - schedule: cron?.[1], - manuallyDispatchable: workflowYaml.includes('workflow_dispatch:'), - }; - } + details[workflow.name] = { + ...workflow, + schedule: cron?.[1], + manuallyDispatchable: workflowYaml.includes('workflow_dispatch:'), + }; + } - return details; -}, { + return details; + }, maxAge: {days: 1}, staleWhileRevalidate: {days: 10}, cacheKey: cacheByRepo, @@ -108,7 +109,7 @@ async function addIndicators(workflowListItem: HTMLAnchorElement): Promise<void> } // Called in `init`, memoized - const workflows = await getWorkflowsDetails(); + const workflows = await workflowDetails.get(); const workflowName = workflowListItem.href.split('/').pop()!; const workflow = workflows[workflowName]; if (!workflow) { @@ -152,7 +153,7 @@ async function addIndicators(workflowListItem: HTMLAnchorElement): Promise<void> async function init(signal: AbortSignal): Promise<false | void> { // Do it as soon as possible, before the page loads - const workflows = await getWorkflowsDetails(); + const workflows = await workflowDetails.get(); if (!workflows) { return false; } |