diff --git a/src/Renderer/Repository/Polling/StreamClient/SystemStreamWatchingClient.ts b/src/Renderer/Repository/Polling/StreamClient/SystemStreamWatchingClient.ts index ce5775be..31247799 100644 --- a/src/Renderer/Repository/Polling/StreamClient/SystemStreamWatchingClient.ts +++ b/src/Renderer/Repository/Polling/StreamClient/SystemStreamWatchingClient.ts @@ -3,12 +3,21 @@ import {UserPrefRepo} from '../../UserPrefRepo'; import {GitHubUserClient} from '../../../Library/GitHub/GitHubUserClient'; import {ArrayUtil} from '../../../Library/Util/ArrayUtil'; +const SEARCH_QUERY_EXPIRES_IN = 10 * 60 * 1000; // 10mins as msec + export class SystemStreamWatchingClient extends StreamClient { + private lastBuildSearchQueriesAt: number = 0; + private lastBuildSearchQueries: string[] = []; + constructor(id: number, name: string, searchedAt: string) { super(id, name, [], searchedAt); } protected async buildSearchQueries() { + if (Date.now() - this.lastBuildSearchQueriesAt < SEARCH_QUERY_EXPIRES_IN) { + return this.lastBuildSearchQueries; + } + const {error, watchings} = await this.fetchWatchings(); if (error) { console.error(error); @@ -19,6 +28,8 @@ export class SystemStreamWatchingClient extends StreamClient { // https://docs.github.com/en/free-pro-team@latest/github/searching-for-information-on-github/troubleshooting-search-queries#limitations-on-query-length const updatedLength = ` updated:>=YYYY-MM-DDThh:mm:ssZ`.length; const queries = ArrayUtil.joinWithMax(watchings.map(w => `repo:${w}`), 256 - updatedLength); + this.lastBuildSearchQueriesAt = Date.now(); + this.lastBuildSearchQueries = queries; return queries; }