admin/plugins/updates: way faster
Massimo Melina committed
Jul 1, 2023 at 13:47 UTC
0e868c0b0c1ef2e74b45bca78f7774bf08c7c428
1 file changed
+8
-5
src/api.plugins.ts
+8
-5
@@ -18,7 +18,7 @@ import {
18
} from './plugins'
19
import _ from 'lodash'
20
import assert from 'assert'
21
-import { Callback, newObj, onOff, waitFor } from './misc'
21
+import { Callback, newObj, onlyTruthy, onOff, waitFor } from './misc'
22
import { ApiError, ApiHandlers, SendListReadable } from './apiMiddleware'
23
import events from './events'
24
import { rm } from 'fs/promises'
@@ -48,19 +48,22 @@ const apis: ApiHandlers = {
48
async get_plugin_updates() {
49
const list = new SendListReadable()
50
setTimeout(async () => {
51
- for (const [folder, repo] of Object.entries(getFolder2repo()))
51
+ const errs = await Promise.all(_.map(getFolder2repo(), async (repo, folder) => {
52
try {
53
- if (!repo) continue
53
+ if (!repo) return
54
//TODO shouldn't we consider other branches here?
55
const online = await readOnlinePlugin(repo)
56
- if (!online.apiRequired || online.badApi) continue
56
+ if (!online.apiRequired || online.badApi) return
57
const disk = getPluginInfo(folder)
58
if (online.version! > disk.version)
59
list.add(online)
60
}
61
catch (err:any) {
62
- list.error(err.code || err.message)
62
+ return err.code || err.message
63
}
64
+ }))
65
+ for (const x of _.uniq(onlyTruthy(errs)))
66
+ list.error(x)
67
list.close()
68
})
69
return list