Fixed duplicated data

This commit is contained in:
Donald Zou
2025-10-24 09:53:40 +08:00
parent 9dd5341fd9
commit 10c9b5635f

View File

@@ -501,15 +501,24 @@ class WireguardConfiguration:
with self.engine.begin() as conn: with self.engine.begin() as conn:
for tempPeer in self.Peers: for tempPeer in self.Peers:
if tempPeer.status == "running": if tempPeer.status == "running":
endpoint = tempPeer.endpoint.rsplit(":", 1) endpoint = tempPeer.endpoint.rsplit(":", 1)
if len(endpoint) == 2 and len(endpoint[0]) > 0: if len(endpoint) == 2 and len(endpoint[0]) > 0:
conn.execute( exist = conn.execute(
self.peersHistoryEndpointTable.insert().values({ self.peersHistoryEndpointTable.select().where(
"id": tempPeer.id, sqlalchemy.and_(
"endpoint": endpoint[0], self.peersHistoryEndpointTable.c.id == tempPeer.id,
"time": datetime.now() self.peersHistoryEndpointTable.c.endpoint == endpoint[0]
}) )
) )
).mappings().fetchone()
if not exist:
conn.execute(
self.peersHistoryEndpointTable.insert().values({
"id": tempPeer.id,
"endpoint": endpoint[0],
"time": datetime.now()
})
)
def addPeers(self, peers: list) -> tuple[bool, list, str]: def addPeers(self, peers: list) -> tuple[bool, list, str]:
result = { result = {