Skip to content

Commit d5686ef

Browse files
committed
feat: added opts.git.cooldown to allow updating plugins on slow connections. Fixes #1656
1 parent 839f9e7 commit d5686ef

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

lua/lazy/core/config.lua

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ M.defaults = {
4141
rate = 2,
4242
duration = 5 * 1000, -- in ms
4343
},
44+
-- Time in seconds to wait before running fetch again for a plugin.
45+
-- Repeated update/check operations will not run again until this
46+
-- cooldown period has passed.
47+
cooldown = 0,
4448
},
4549
pkg = {
4650
enabled = true,

lua/lazy/manage/task/git.lua

+15-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ function throttle.wait()
4040
end
4141
end
4242

43+
---@param plugin LazyPlugin
44+
local function cooldown(plugin)
45+
if not plugin._.last_check then
46+
return false
47+
end
48+
local delta = (vim.uv.now() - plugin._.last_check) / 1000
49+
return delta < Config.options.git.cooldown
50+
end
51+
4352
---@type table<string, LazyTaskDef>
4453
local M = {}
4554

@@ -266,7 +275,7 @@ M.status = {
266275
-- fetches all needed origin branches
267276
M.fetch = {
268277
skip = function(plugin)
269-
return not plugin._.installed or plugin._.is_local
278+
return not plugin._.installed or plugin._.is_local or cooldown(plugin)
270279
end,
271280

272281
---@async
@@ -287,6 +296,11 @@ M.fetch = {
287296
self:spawn("git", {
288297
args = args,
289298
cwd = self.plugin.dir,
299+
on_exit = function(ok)
300+
if ok then
301+
self.plugin._.last_check = vim.uv.now()
302+
end
303+
end,
290304
})
291305
end,
292306
}

lua/lazy/types.lua

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
---@field tasks? LazyTask[]
2121
---@field updated? {from:string, to:string}
2222
---@field updates? {from:GitInfo, to:GitInfo}
23+
---@field last_check? number
2324
---@field working? boolean
2425
---@field pkg? LazyPkg
2526

0 commit comments

Comments
 (0)