Skip to content

Commit 898cf8a

Browse files
authored
fix: obsoleteRepos query to use repositories instead of insightsProject.repositories (#3824)
1 parent 70b996d commit 898cf8a

1 file changed

Lines changed: 17 additions & 21 deletions

File tree

  • services/libs/data-access-layer/src/security_insights

services/libs/data-access-layer/src/security_insights/index.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,27 @@ export async function findObsoleteReposQx(
1515
limit = 1000,
1616
): Promise<ISecurityInsightsObsoleteRepo[]> {
1717
const failedReposSubquery =
18-
failedRepos.length > 0 ? 'and all_repos."repoUrl" not in ($(failedRepos:csv))' : ''
18+
failedRepos.length > 0 ? 'and r."url" not in ($(failedRepos:csv))' : ''
1919

2020
const repos: ISecurityInsightsObsoleteRepo[] = await qx.select(
2121
`
22-
with all_repos as (
23-
select
24-
id as "insightsProjectId",
25-
slug as "insightsProjectSlug",
26-
unnest(repositories) as "repoUrl"
27-
from "insightsProjects"
28-
)
2922
select distinct
30-
"insightsProjectId",
31-
"insightsProjectSlug",
32-
"repoUrl"
33-
from all_repos
34-
where not exists (
35-
select 1
36-
from "securityInsightsEvaluationSuites" s
37-
where s.repo = all_repos."repoUrl"
38-
AND EXTRACT(EPOCH FROM (now() - s."updatedAt")) < $(insightsObsoleteAfterSeconds)
39-
)
40-
and "repoUrl" like 'https://github.com%'
41-
${failedReposSubquery}
42-
order by "repoUrl" asc
23+
ip.id as "insightsProjectId",
24+
ip.slug as "insightsProjectSlug",
25+
r.url as "repoUrl"
26+
from "insightsProjects" ip
27+
join "repositories" r on r."insightsProjectId" = ip.id
28+
where r."deletedAt" is null
29+
and r."excluded" = false
30+
and r.url like 'https://github.com%'
31+
and not exists (
32+
select 1
33+
from "securityInsightsEvaluationSuites" s
34+
where s.repo = r.url
35+
AND EXTRACT(EPOCH FROM (now() - s."updatedAt")) < $(insightsObsoleteAfterSeconds)
36+
)
37+
${failedReposSubquery}
38+
order by r.url asc
4339
limit $(limit)
4440
`,
4541
{

0 commit comments

Comments
 (0)