chore(xo-server/remotes): store handler instances
This commit is contained in:
parent
011cc7ad65
commit
76f75401ee
@ -14,6 +14,7 @@ export default class {
|
|||||||
prefix: 'xo:remote',
|
prefix: 'xo:remote',
|
||||||
indexes: ['enabled'],
|
indexes: ['enabled'],
|
||||||
})
|
})
|
||||||
|
this._handlers = { __proto__: null }
|
||||||
|
|
||||||
xo.on('clean', () => this._remotes.rebuildIndexes())
|
xo.on('clean', () => this._remotes.rebuildIndexes())
|
||||||
xo.on('start', async () => {
|
xo.on('start', async () => {
|
||||||
@ -32,10 +33,10 @@ export default class {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
xo.on('stop', async () => {
|
xo.on('stop', async () => {
|
||||||
const remotes = await this.getAllRemotes()
|
const handlers = this._handlers
|
||||||
for (const remote of remotes) {
|
for (const id in handlers) {
|
||||||
try {
|
try {
|
||||||
;(await this.getRemoteHandler(remote, true)).forget()
|
await handlers[id].forget()
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -50,7 +51,13 @@ export default class {
|
|||||||
throw new Error('remote is disabled')
|
throw new Error('remote is disabled')
|
||||||
}
|
}
|
||||||
|
|
||||||
return getHandler(remote)
|
const { id } = remote
|
||||||
|
const handlers = this._handlers
|
||||||
|
let handler = handlers[id]
|
||||||
|
if (handler === undefined) {
|
||||||
|
handler = handlers[id] = getHandler(remote)
|
||||||
|
}
|
||||||
|
return handler
|
||||||
}
|
}
|
||||||
|
|
||||||
async testRemote (remote) {
|
async testRemote (remote) {
|
||||||
|
Loading…
Reference in New Issue
Block a user