@@ -134,23 +134,27 @@ fn build_summary(b: &Build) -> Value {
134134 } )
135135}
136136
137- /// This month's credits per project, with how much came from the open source pool, for the Usage tab.
137+ /// This month's credits per project, with how much came from the open source pool, for the Usage tab. A deleted
138+ /// project stays listed (`deleted`) while it has credits this month: what it used still counts.
138139async fn usage_by_project ( org_id : i64 ) -> laravel:: Result < Vec < Value > > {
139140 let since = crate :: domain:: credits:: month_start ( ) ;
140141 let rows = db:: query!(
141142 "SELECT p.slug, p.name, (p.open_source AND p.public AND NOT p.open_source_withdrawn) AS open_source, \
143+ p.deleted_at IS NOT NULL AS deleted, \
142144 COALESCE(-SUM(t.amount), 0)::bigint AS credits, COALESCE(SUM(t.open_source_credits), 0)::bigint AS pool \
143145 FROM projects p LEFT JOIN credit_transactions t ON t.project_id = p.id AND t.created_at >= {since} \
144146 AND t.kind IN ('build', 'render', 'gallery') \
145- WHERE p.organization_id = {org_id} GROUP BY p.id ORDER BY credits DESC, p.slug"
147+ WHERE p.organization_id = {org_id} GROUP BY p.id \
148+ HAVING p.deleted_at IS NULL OR COUNT(t.id) > 0 ORDER BY credits DESC, p.slug, p.id"
146149 )
147150 . select ( )
148151 . await ?;
149152 rows. iter ( )
150153 . map ( |r| {
151154 Ok ( json ! ( {
152155 "project" : r. try_get:: <String >( "slug" ) ?, "name" : r. try_get:: <String >( "name" ) ?,
153- "open_source" : r. try_get:: <bool >( "open_source" ) ?, "credits" : r. try_get:: <i64 >( "credits" ) ?,
156+ "open_source" : r. try_get:: <bool >( "open_source" ) ?, "deleted" : r. try_get:: <bool >( "deleted" ) ?,
157+ "credits" : r. try_get:: <i64 >( "credits" ) ?,
154158 "open_source_credits" : r. try_get:: <i64 >( "pool" ) ?,
155159 } ) )
156160 } )
@@ -168,13 +172,14 @@ pub async fn show(
168172 let ( org_id, _, role) = super :: invitations:: org_role ( & user, & org) . await ?;
169173 let org = Organization :: find_or_fail ( org_id) . await ?;
170174 let admin = role == Role :: Admin ;
171- let projects: Vec < ( i64 , String , String ) > =
172- db:: query!( "SELECT id, slug, name FROM projects WHERE organization_id = {org_id} ORDER BY slug" )
173- . select ( )
174- . await ?
175- . iter ( )
176- . map ( |r| Ok ( ( r. try_get ( "id" ) ?, r. try_get ( "slug" ) ?, r. try_get ( "name" ) ?) ) )
177- . collect :: < laravel:: Result < _ > > ( ) ?;
175+ let projects: Vec < ( i64 , String , String ) > = db:: query!(
176+ "SELECT id, slug, name FROM projects WHERE organization_id = {org_id} AND deleted_at IS NULL ORDER BY slug"
177+ )
178+ . select ( )
179+ . await ?
180+ . iter ( )
181+ . map ( |r| Ok ( ( r. try_get ( "id" ) ?, r. try_get ( "slug" ) ?, r. try_get ( "name" ) ?) ) )
182+ . collect :: < laravel:: Result < _ > > ( ) ?;
178183 let mut list = Vec :: new ( ) ;
179184 for ( id, slug, name) in projects {
180185 let last = crate :: domain:: builds:: recent ( id, None , false , 1 ) . await ?;
0 commit comments