@@ -666,8 +666,7 @@ function Plugin:load(opts)
666
666
return false
667
667
end
668
668
669
- -- Prevent recursive loading
670
- -- Set loaded to true before actual loading to prevent infinite loops
669
+ -- Set loaded flag to prevent recursive loading
671
670
self .loaded = true
672
671
vim .g .strive_loaded = vim .g .strive_loaded + 1
673
672
@@ -677,23 +676,42 @@ function Plugin:load(opts)
677
676
678
677
self :packadd ()
679
678
self :load_scripts (opts and opts .script_cb or nil )
680
-
681
679
self :call_setup ()
682
680
681
+ self .status = STATUS .LOADED
682
+ pcall (api .nvim_del_augroup_by_name , ' strive_' .. self .plugin_name )
683
+
684
+ -- Load dependencies in parallel
683
685
if # self .dependencies > 0 then
684
- for _ , dep in ipairs (self .dependencies ) do
685
- if not dep .loaded then
686
- dep :load ()
686
+ Async .async (function ()
687
+ local dependency_promises = {}
688
+ for _ , dep in ipairs (self .dependencies ) do
689
+ if not dep .loaded then
690
+ table.insert (dependency_promises , function (cb )
691
+ Async .async (function ()
692
+ local success = dep :load ()
693
+ cb (Result .success (success ))
694
+ end )()
695
+ end )
696
+ end
687
697
end
688
- end
689
- end
690
698
691
- if self .config_opts then
692
- load_opts (self .config_opts )
699
+ if # dependency_promises > 0 then
700
+ Async .await (Async .all (dependency_promises ))
701
+ end
702
+
703
+ -- Run config after all dependencies are loaded
704
+ if self .config_opts then
705
+ load_opts (self .config_opts )
706
+ end
707
+ end )()
708
+ else
709
+ -- No dependencies, run config immediately
710
+ if self .config_opts then
711
+ load_opts (self .config_opts )
712
+ end
693
713
end
694
714
695
- self .status = STATUS .LOADED
696
- pcall (api .nvim_del_augroup_by_name , ' strive_' .. self .plugin_name )
697
715
return true
698
716
end
699
717
@@ -1357,107 +1375,69 @@ function M.update()
1357
1375
M .log (' info' , ' Checking for updates...' )
1358
1376
local plugins_to_update = {}
1359
1377
1360
- -- Add Strive plugin itself to the update list
1361
- local strive_plugin = Plugin .new ({
1362
- name = ' nvimdev/strive' ,
1363
- plugin_name = ' strive' ,
1364
- is_lazy = true ,
1365
- })
1366
-
1367
- -- Find plugins that need updating with proper error handling
1368
1378
for _ , plugin in ipairs (plugins ) do
1369
1379
if plugin .is_remote and not plugin .is_local then
1370
- local result = Async .try_await (plugin :is_installed ())
1371
-
1372
- if result .success and result .value then
1380
+ local installed = Async .await (plugin :is_installed ())
1381
+ if installed then
1373
1382
table.insert (plugins_to_update , plugin )
1374
- elseif not result .success then
1375
- M .log (
1376
- ' error' ,
1377
- string.format (
1378
- ' Error checking if %s is installed: %s' ,
1379
- plugin .name ,
1380
- tostring (result .error )
1381
- )
1382
- )
1383
1383
end
1384
1384
end
1385
1385
end
1386
1386
1387
- -- Check if Strive itself is installed
1388
- local strive_result = Async .try_await (strive_plugin :is_installed ())
1389
- if strive_result .success and strive_result .value then
1390
- table.insert (plugins_to_update , strive_plugin )
1391
- end
1392
-
1393
1387
if # plugins_to_update == 0 then
1394
- M .log (' debug ' , ' No plugins to update.' )
1388
+ M .log (' info ' , ' No plugins to update.' )
1395
1389
return
1396
1390
end
1397
1391
1398
1392
ui :open ()
1399
1393
1400
- local updated_count = 0
1401
- local skipped_count = 0
1402
- local error_count = 0
1394
+ -- First, fetch all repositories in parallel
1395
+ local fetch_promises = {}
1396
+ for _ , plugin in ipairs (plugins_to_update ) do
1397
+ local path = plugin :get_path ()
1398
+ table.insert (
1399
+ fetch_promises ,
1400
+ Async .system ({
1401
+ ' git' ,
1402
+ ' -C' ,
1403
+ path ,
1404
+ ' fetch' ,
1405
+ ' --quiet' ,
1406
+ ' origin' ,
1407
+ })
1408
+ )
1409
+ end
1403
1410
1404
- -- Update plugins in batches for better control and error handling
1405
- local batch_size = DEFAULT_SETTINGS .max_concurrent_tasks
1406
- local total_batches = math.ceil (# plugins_to_update / batch_size )
1411
+ -- Wait for all fetches to complete
1412
+ Async .await (Async .all (fetch_promises ))
1407
1413
1408
- for batch = 1 , total_batches do
1409
- local start_idx = (batch - 1 ) * batch_size + 1
1410
- local end_idx = math.min (batch * batch_size , # plugins_to_update )
1411
- local current_batch = {}
1414
+ -- Now process actual updates with TaskQueue
1415
+ local task_queue = TaskQueue .new (DEFAULT_SETTINGS .max_concurrent_tasks )
1412
1416
1413
- for i = start_idx , end_idx do
1414
- local plugin = plugins_to_update [ i ]
1415
- table.insert ( current_batch , plugin : update () )
1416
- end
1417
+ for _ , plugin in ipairs ( plugins_to_update ) do
1418
+ task_queue : enqueue ( function ( done )
1419
+ Async . async ( function ( )
1420
+ local has_updates = Async . await ( plugin : has_updates ())
1417
1421
1418
- -- Wait for current batch to complete with error handling
1419
- local batch_result = Async .try_await (Async .all (current_batch ))
1420
-
1421
- if batch_result .success then
1422
- -- Process successful results
1423
- for _ , result in ipairs (batch_result .value ) do
1424
- local success , status = unpack (result )
1425
- if success then
1426
- if status == ' updated' then
1427
- updated_count = updated_count + 1
1428
- elseif status == ' up_to_date' then
1429
- skipped_count = skipped_count + 1
1430
- end
1422
+ if has_updates then
1423
+ plugin .status = STATUS .UPDATING
1424
+ ui :update_entry (plugin .name , plugin .status , ' Updating...' )
1425
+ Async .await (plugin :update ())
1431
1426
else
1432
- error_count = error_count + 1
1427
+ plugin .status = STATUS .UPDATED
1428
+ ui :update_entry (plugin .name , plugin .status , ' Already up to date' )
1433
1429
end
1434
- end
1435
- else
1436
- M .log (' error' , string.format (' Error updating batch: %s' , tostring (batch_result .error )))
1437
- error_count = error_count + (end_idx - start_idx + 1 )
1438
- end
1439
- end
1440
1430
1441
- -- Report results
1442
- if updated_count > 0 then
1443
- M .log (
1444
- ' info' ,
1445
- string.format (
1446
- ' Updated %d plugins, %d already up to date, %d errors.' ,
1447
- updated_count ,
1448
- skipped_count ,
1449
- error_count
1450
- )
1451
- )
1452
- elseif error_count > 0 then
1453
- M .log (' warn' , string.format (' No plugins updated, %d errors occurred.' , error_count ))
1454
- else
1455
- M .log (' info' , ' All plugins already up to date.' )
1431
+ done ()
1432
+ end )()
1433
+ end )
1456
1434
end
1457
1435
1458
- -- Close UI after a delay
1459
- Async .await (Async .delay (2000 ))
1460
- ui :close ()
1436
+ task_queue :on_complete (function ()
1437
+ M .log (' info' , ' Update completed' )
1438
+ Async .await (Async .delay (2000 ))
1439
+ ui :close ()
1440
+ end )
1461
1441
end )()
1462
1442
end
1463
1443
0 commit comments