diff options
author | 2020-05-27 13:25:29 -0400 | |
---|---|---|
committer | 2020-05-27 19:25:29 +0200 | |
commit | a49cc0d0c7a32a98b55ded205d97cade23fce87a (patch) | |
tree | e18fb98ea38d626f8ab20d2dc2f6fa88b1054cbf /source/features/highlight-collaborators-and-own-discussions.tsx | |
parent | 3e0d92f5c7e1e5182d3ffef48526e8d16d1e913d (diff) | |
download | refined-github-a49cc0d0c7a32a98b55ded205d97cade23fce87a.tar.gz refined-github-a49cc0d0c7a32a98b55ded205d97cade23fce87a.tar.zst refined-github-a49cc0d0c7a32a98b55ded205d97cade23fce87a.zip |
Add cache to `highlight-collaborators-and-own-discussions` (#3143)
Diffstat (limited to 'source/features/highlight-collaborators-and-own-discussions.tsx')
-rw-r--r-- | source/features/highlight-collaborators-and-own-discussions.tsx | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/source/features/highlight-collaborators-and-own-discussions.tsx b/source/features/highlight-collaborators-and-own-discussions.tsx index 81cf393c..f0357809 100644 --- a/source/features/highlight-collaborators-and-own-discussions.tsx +++ b/source/features/highlight-collaborators-and-own-discussions.tsx @@ -1,4 +1,5 @@ import './highlight-collaborators-and-own-discussions.css'; +import cache from 'webext-storage-cache'; import select from 'select-dom'; import * as pageDetect from 'github-url-detection'; @@ -6,16 +7,24 @@ import features from '.'; import fetchDom from '../helpers/fetch-dom'; import {getRepoURL, getUsername} from '../github-helpers'; +const getCollaborators = cache.function(async (): Promise<string[]> => { + const dom = await fetchDom(getRepoURL() + '/issues/show_menu_content?partial=issues/filters/authors_content'); + return select + .all<HTMLImageElement>('.SelectMenu-item [alt]', dom) + .map(avatar => avatar.alt.slice(1)); +}, { + maxAge: 5, + staleWhileRevalidate: 20, + cacheKey: () => 'repo-collaborators:' + getRepoURL() +}); + async function highlightCollaborators(): Promise<false | void> { const authors = select.all('.js-issue-row [data-hovercard-type="user"]'); if (authors.length === 0) { return false; } - const dom = await fetchDom(getRepoURL() + '/issues/show_menu_content?partial=issues/filters/authors_content'); - const collaborators = select.all<HTMLImageElement>('.SelectMenu-item [alt]', dom).map(collaborator => { - return collaborator.alt.slice(1); - }); + const collaborators = await getCollaborators(); for (const author of authors) { if (collaborators.includes(author.textContent!.trim())) { @@ -47,4 +56,3 @@ features.add({ ], init: highlightSelf }); - |