From fec20ed38177d785209880cb3019f2fb7bf527aa Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Sun, 25 Aug 2024 15:59:48 +0800 Subject: [PATCH] Reduced the time to open the config file --- src/dashboard.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/dashboard.py b/src/dashboard.py index e132bcc..1d27526 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -598,6 +598,7 @@ class WireguardConfiguration: return changed def __getPeers(self): + if self.configurationFileChanged(): self.Peers = [] with open(os.path.join(WG_CONF_PATH, f'{self.Name}.conf'), 'r') as configFile: @@ -670,6 +671,11 @@ class WireguardConfiguration: self.Peers.append(Peer(checkIfExist, self)) except Exception as e: print(f"[WGDashboard] {self.Name} Error: {str(e)}") + else: + self.Peers.clear() + checkIfExist = sqlSelect("SELECT * FROM '%s'" % self.Name).fetchall() + for i in checkIfExist: + self.Peers.append(Peer(i, self)) def addPeers(self, peers: list): @@ -809,12 +815,11 @@ class WireguardConfiguration: else: status = "stopped" if int(latestHandshake[count + 1]) > 0: - sqldb.execute("UPDATE '%s' SET latest_handshake = ?, status = ? WHERE id= ?" % self.Name + sqlUpdate("UPDATE '%s' SET latest_handshake = ?, status = ? WHERE id= ?" % self.Name , (str(minus).split(".", maxsplit=1)[0], status, latestHandshake[count],)) else: - sqldb.execute("UPDATE '%s' SET latest_handshake = 'No Handshake', status = ? WHERE id= ?" % self.Name + sqlUpdate("UPDATE '%s' SET latest_handshake = 'No Handshake', status = ? WHERE id= ?" % self.Name , (status, latestHandshake[count],)) - sqldb.commit() count += 2