@@ -521,9 +521,14 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
521521 } ) ;
522522
523523 const listProjectRows = SqlSchema . findAll ( {
524- Request : Schema . Void ,
524+ Request : Schema . UndefinedOr (
525+ Schema . Struct ( {
526+ activeOnly : Schema . Boolean ,
527+ projectIds : Schema . optional ( Schema . Array ( ProjectId ) ) ,
528+ } ) ,
529+ ) ,
525530 Result : ProjectionProjectDbRowSchema ,
526- execute : ( ) =>
531+ execute : ( filter ) =>
527532 sql `
528533 SELECT
529534 project_id AS "projectId",
@@ -539,6 +544,8 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
539544 updated_at AS "updatedAt",
540545 deleted_at AS "deletedAt"
541546 FROM projection_projects
547+ WHERE ${ filter ?. activeOnly === true ? sql `deleted_at IS NULL` : sql `1 = 1` }
548+ AND ${ filter ?. projectIds === undefined ? sql `1 = 1` : sql . in ( "project_id" , filter . projectIds ) }
542549 ORDER BY created_at ASC, project_id ASC
543550 ` ,
544551 } ) ;
@@ -2947,25 +2954,24 @@ pending_approval_requests AS (
29472954 ) ,
29482955 ) ;
29492956
2950- const getProjectShells : ProjectionSnapshotQueryShape [ "getProjectShells" ] = ( projectIds ) =>
2951- listProjectRows ( undefined ) . pipe (
2957+ const getProjectShells : ProjectionSnapshotQueryShape [ "getProjectShells" ] = ( projectIds ) => {
2958+ if ( projectIds ?. length === 0 ) return Effect . succeed ( [ ] ) ;
2959+ return listProjectRows ( { activeOnly : true , projectIds } ) . pipe (
29522960 Effect . mapError (
29532961 toPersistenceSqlOrDecodeError (
29542962 "ProjectionSnapshotQuery.getProjectShells:query" ,
29552963 "ProjectionSnapshotQuery.getProjectShells:decodeRows" ,
29562964 ) ,
29572965 ) ,
2958- Effect . flatMap ( ( rows ) => {
2959- const projects = rows . filter (
2960- ( row ) => row . deletedAt === null && ( projectIds ?. includes ( row . projectId ) ?? true ) ,
2961- ) ;
2962- return resolveRepositoryIdentitiesForProjects ( projects ) . pipe (
2966+ Effect . flatMap ( ( projects ) =>
2967+ resolveRepositoryIdentitiesForProjects ( projects ) . pipe (
29632968 Effect . map ( ( identities ) =>
29642969 projects . map ( ( row ) => mapProjectShellRow ( row , identities . get ( row . projectId ) ?? null ) ) ,
29652970 ) ,
2966- ) ;
2967- } ) ,
2971+ ) ,
2972+ ) ,
29682973 ) ;
2974+ } ;
29692975
29702976 const getProjectShellById : ProjectionSnapshotQueryShape [ "getProjectShellById" ] = ( projectId ) =>
29712977 getActiveProjectRowById ( { projectId } ) . pipe (
0 commit comments