@@ -290,50 +290,32 @@ impl LDNApplication {
290
290
}
291
291
292
292
pub async fn all_applications ( ) -> Result < Vec < ( ApplicationFile , String , String ) > , Vec < LDNError > > {
293
- //TODO: Avoid filtering by allocators. Simply get all active & merged applications from the database.
294
- let allocators = match database:: allocators:: get_allocators ( ) . await {
295
- Ok ( allocs) => allocs,
296
- Err ( e) => return Err ( vec ! [ LDNError :: Load ( format!( "Failed to retrieve allocators: {}" , e) ) ] ) ,
297
- } ; let mut all_apps: Vec < ( ApplicationFile , String , String ) > = Vec :: new ( ) ;
298
- let mut errors: Vec < LDNError > = Vec :: new ( ) ;
299
-
300
- for allocator in allocators {
301
- match Self :: active ( allocator. owner . clone ( ) , allocator. repo . clone ( ) , None ) . await {
302
- Ok ( apps) => {
303
- for app in apps {
304
- all_apps. push ( ( app, allocator. owner . clone ( ) , allocator. repo . clone ( ) ) ) ;
305
- }
306
- } ,
307
- Err ( e) => {
308
- errors. push ( e) ;
309
- eprintln ! ( "Failed to process active applications for allocator {}:{}" , allocator. repo, allocator. owner) ;
310
- } ,
311
- }
312
-
313
- match Self :: merged ( allocator. owner . clone ( ) , allocator. repo . clone ( ) ) . await {
314
- Ok ( merged_apps) => {
315
- for ( _, app) in merged_apps {
316
- all_apps. push ( ( app, allocator. owner . clone ( ) , allocator. repo . clone ( ) ) ) ;
317
- }
318
- } ,
319
- Err ( e) => {
320
- errors. push ( e) ;
321
- eprintln ! ( "Failed to process merged applications for allocator {}:{}" , allocator. repo, allocator. owner) ;
322
- } ,
323
- }
324
- }
325
-
326
- if errors. is_empty ( ) {
327
- Ok ( all_apps)
328
- } else {
329
- Err ( errors)
293
+ let db_apps = database:: applications:: get_applications ( ) . await ;
294
+ let mut all_apps: Vec < ( ApplicationFile , String , String ) > = Vec :: new ( ) ;
295
+ match db_apps {
296
+ Ok ( apps) => {
297
+ for app in apps {
298
+ let app_file = match ApplicationFile :: from_str ( & app. application . unwrap ( ) ) {
299
+ Ok ( app) => app,
300
+ Err ( e) => {
301
+ return Err ( vec ! [ LDNError :: Load ( format!( "Failed to parse application file from DB /// {}" , e) ) ] ) ;
302
+ }
303
+ } ;
304
+ all_apps. push ( ( app_file, app. owner , app. repo ) ) ;
305
+ }
306
+ return Ok ( all_apps) ;
307
+ } ,
308
+ Err ( e) => {
309
+ return Err ( vec ! [ LDNError :: Load ( format!( "Failed to retrieve applications from the database /// {}" , e) ) ] ) ;
310
+ } ,
330
311
}
312
+
331
313
}
332
314
333
315
334
316
pub async fn active ( owner : String , repo : String , filter : Option < String > ) -> Result < Vec < ApplicationFile > , LDNError > {
335
317
// Get all active applications from the database.
336
- let active_apps_result = database:: applications:: get_active_applications ( owner, repo) . await ;
318
+ let active_apps_result = database:: applications:: get_active_applications ( Some ( owner) , Some ( repo) ) . await ;
337
319
338
320
// Handle errors in getting active applications.
339
321
let active_apps = match active_apps_result {
@@ -355,7 +337,8 @@ impl LDNApplication {
355
337
if let Some ( app_json) = app_model. application {
356
338
match from_str :: < ApplicationFile > ( & app_json) {
357
339
Ok ( app) => apps. push ( app) ,
358
- Err ( e) => return Err ( LDNError :: Load ( format ! ( "Failed to parse application file: {}" , e) ) ) ,
340
+ //if error, don't push into apps
341
+ Err ( _) => { }
359
342
}
360
343
}
361
344
}
@@ -934,7 +917,7 @@ impl LDNApplication {
934
917
935
918
pub async fn merged ( owner : String , repo : String ) -> Result < Vec < ( ApplicationGithubInfo , ApplicationFile ) > , LDNError > {
936
919
// Retrieve all applications in the main branch from the database.
937
- let merged_apps_result = database:: applications:: get_merged_applications ( owner. clone ( ) , repo. clone ( ) ) . await ;
920
+ let merged_apps_result = database:: applications:: get_merged_applications ( Some ( owner. clone ( ) ) , Some ( repo. clone ( ) ) ) . await ;
938
921
939
922
// Handle errors in getting applications from the main branch.
940
923
let merged_app_models = match merged_apps_result {
@@ -950,7 +933,7 @@ impl LDNApplication {
950
933
if let Some ( app_json) = app_model. application {
951
934
match from_str :: < ApplicationFile > ( & app_json) {
952
935
Ok ( app) => merged_apps. push ( ( ApplicationGithubInfo { sha : app_model. sha . unwrap ( ) , path : app_model. path . unwrap ( ) } , app) ) ,
953
- Err ( e ) => return Err ( LDNError :: Load ( format ! ( "Failed to parse application file: {}" , e ) ) ) ,
936
+ Err ( _ ) => { } ,
954
937
}
955
938
}
956
939
}
@@ -1807,7 +1790,7 @@ Your Datacap Allocation Request has been {} by the Notary
1807
1790
1808
1791
pub async fn cache_renewal_active ( owner : String , repo : String ) -> Result < ( ) , LDNError > {
1809
1792
let active_from_gh: Vec < ApplicationFileWithDate > = LDNApplication :: active_apps_with_last_update ( owner. clone ( ) , repo. clone ( ) , None ) . await ?;
1810
- let active_from_db: Vec < ApplicationModel > = database:: applications:: get_active_applications ( owner. clone ( ) , repo. clone ( ) ) . await . unwrap ( ) ;
1793
+ let active_from_db: Vec < ApplicationModel > = database:: applications:: get_active_applications ( Some ( owner. clone ( ) ) , Some ( repo. clone ( ) ) ) . await . unwrap ( ) ;
1811
1794
1812
1795
let mut db_apps_set: HashSet < String > = HashSet :: new ( ) ;
1813
1796
let mut processed_gh_apps: HashSet < String > = HashSet :: new ( ) ;
@@ -1864,7 +1847,7 @@ Your Datacap Allocation Request has been {} by the Notary
1864
1847
1865
1848
pub async fn cache_renewal_merged ( owner : String , repo : String ) -> Result < ( ) , LDNError > {
1866
1849
let merged_from_gh: Vec < ApplicationFileWithDate > = LDNApplication :: merged_apps_with_last_update ( owner. clone ( ) , repo. clone ( ) , None ) . await ?;
1867
- let merged_from_db: Vec < ApplicationModel > = database:: applications:: get_merged_applications ( owner. clone ( ) , repo. clone ( ) ) . await . unwrap ( ) ;
1850
+ let merged_from_db: Vec < ApplicationModel > = database:: applications:: get_merged_applications ( Some ( owner. clone ( ) ) , Some ( repo. clone ( ) ) ) . await . unwrap ( ) ;
1868
1851
1869
1852
let mut db_apps_set: HashSet < String > = HashSet :: new ( ) ;
1870
1853
let mut processed_gh_apps: HashSet < String > = HashSet :: new ( ) ;
0 commit comments