Skip to content

Commit

Permalink
optimized finding client index
Browse files Browse the repository at this point in the history
Co-Authored-By: Alireza Ahmadi <alireza7@gmail.com>
  • Loading branch information
MHSanaei and alireza0 committed Aug 29, 2023
1 parent 9c231a4 commit 6aeedac
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions web/html/xui/inbounds.html
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@
openEditClient(dbInboundId, client) {
dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
clients = this.getInboundClients(dbInbound);
index = this.findIndexOfClient(clients, client);
index = this.findIndexOfClient(dbInbound.protocol, clients, client);
clientModal.show({
title: '{{ i18n "pages.client.edit"}}',
okText: '{{ i18n "pages.client.submitEdit"}}',
Expand All @@ -725,8 +725,13 @@
isEdit: true
});
},
findIndexOfClient(clients, client) {
return clients.findIndex(item => JSON.stringify(item) === JSON.stringify(client));
findIndexOfClient(protocol, clients, client) {
switch (protocol) {
case Protocols.TROJAN:
case Protocols.SHADOWSOCKS:
return clients.findIndex(item => item.password === client.password && item.email === client.email);
default: return clients.findIndex(item => item.id === client.id && item.email === client.email);
}
},
async addClient(clients, dbInboundId) {
const data = {
Expand Down Expand Up @@ -832,8 +837,7 @@
dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
inbound = dbInbound.toInbound();
clients = this.getClients(dbInbound.protocol, inbound.settings);
client.enable = !client.enable; // For finding correct index in findIndexOfClient() function
index = this.findIndexOfClient(clients, client);
index = this.findIndexOfClient(dbInbound.protocol, clients, client);
clients[index].enable = !clients[index].enable;
clientId = this.getClientId(dbInbound.protocol, clients[index]);
await this.updateClient(clients[index], dbInboundId, clientId);
Expand Down

0 comments on commit 6aeedac

Please sign in to comment.