@@ -666,8 +666,7 @@ function Plugin:load(opts)
666666 return false
667667 end
668668
669- -- Prevent recursive loading
670- -- Set loaded to true before actual loading to prevent infinite loops
669+ -- Set loaded flag to prevent recursive loading
671670 self .loaded = true
672671 vim .g .strive_loaded = vim .g .strive_loaded + 1
673672
@@ -677,23 +676,42 @@ function Plugin:load(opts)
677676
678677 self :packadd ()
679678 self :load_scripts (opts and opts .script_cb or nil )
680-
681679 self :call_setup ()
682680
681+ self .status = STATUS .LOADED
682+ pcall (api .nvim_del_augroup_by_name , ' strive_' .. self .plugin_name )
683+
684+ -- Load dependencies in parallel
683685 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
687697 end
688- end
689- end
690698
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
693713 end
694714
695- self .status = STATUS .LOADED
696- pcall (api .nvim_del_augroup_by_name , ' strive_' .. self .plugin_name )
697715 return true
698716end
699717
@@ -1357,107 +1375,69 @@ function M.update()
13571375 M .log (' info' , ' Checking for updates...' )
13581376 local plugins_to_update = {}
13591377
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
13681378 for _ , plugin in ipairs (plugins ) do
13691379 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
13731382 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- )
13831383 end
13841384 end
13851385 end
13861386
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-
13931387 if # plugins_to_update == 0 then
1394- M .log (' debug ' , ' No plugins to update.' )
1388+ M .log (' info ' , ' No plugins to update.' )
13951389 return
13961390 end
13971391
13981392 ui :open ()
13991393
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
14031410
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 ))
14071413
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 )
14121416
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 ())
14171421
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 ())
14311426 else
1432- error_count = error_count + 1
1427+ plugin .status = STATUS .UPDATED
1428+ ui :update_entry (plugin .name , plugin .status , ' Already up to date' )
14331429 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
14401430
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 )
14561434 end
14571435
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 )
14611441 end )()
14621442end
14631443
0 commit comments