mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Optimize looping for server list nav
This commit is contained in:
parent
db06eca12e
commit
a76833b409
@ -209,17 +209,18 @@ class PanelHandler(BaseHandler):
|
|||||||
page_servers = []
|
page_servers = []
|
||||||
server_ids = []
|
server_ids = []
|
||||||
|
|
||||||
for server_id in user_order:
|
for server_id in user_order[:]:
|
||||||
for server in defined_servers:
|
for server in defined_servers[:]:
|
||||||
if str(server['server_id']) == str(server_id):
|
if str(server['server_id']) == str(server_id):
|
||||||
page_servers.append(server)
|
page_servers.append(server)
|
||||||
|
user_order.remove(server_id)
|
||||||
|
defined_servers.remove(server)
|
||||||
|
|
||||||
for server in defined_servers:
|
for server in defined_servers:
|
||||||
server_ids.append(str(server['server_id']))
|
server_ids.append(str(server['server_id']))
|
||||||
if server not in page_servers:
|
if server not in page_servers:
|
||||||
page_servers.append(server)
|
page_servers.append(server)
|
||||||
for server_id in user_order:
|
for server_id in user_order[:]:
|
||||||
#remove IDs in list that user no longer has access to
|
#remove IDs in list that user no longer has access to
|
||||||
if str(server_id) not in server_ids:
|
if str(server_id) not in server_ids:
|
||||||
user_order.remove(server_id)
|
user_order.remove(server_id)
|
||||||
@ -336,49 +337,40 @@ class PanelHandler(BaseHandler):
|
|||||||
server_ids = []
|
server_ids = []
|
||||||
un_used_servers = page_data['servers']
|
un_used_servers = page_data['servers']
|
||||||
flag = 0
|
flag = 0
|
||||||
|
for server_id in user_order[:]:
|
||||||
|
for server in un_used_servers[:]:
|
||||||
|
if flag == 0:
|
||||||
|
server['stats']['downloading'] = self.controller.servers.get_download_status(
|
||||||
|
str(server['stats']['server_id']['server_id']))
|
||||||
|
server['stats']['crashed'] = self.controller.servers.is_crashed(
|
||||||
|
str(server['stats']['server_id']['server_id']))
|
||||||
|
try:
|
||||||
|
server['stats']['waiting_start'] = self.controller.servers.get_waiting_start(
|
||||||
|
str(server['stats']['server_id']['server_id']))
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to get server waiting to start: {e}")
|
||||||
|
server['stats']['waiting_start'] = False
|
||||||
|
|
||||||
user_order = self.controller.users.get_user_by_id(exec_user['user_id'])
|
|
||||||
user_order = user_order['server_order'].split(',')
|
|
||||||
page_servers = []
|
|
||||||
server_ids = []
|
|
||||||
|
|
||||||
for server_id in user_order:
|
|
||||||
for server in page_data['servers']:
|
|
||||||
if str(server['server_data']['server_id']) == str(server_id):
|
if str(server['server_data']['server_id']) == str(server_id):
|
||||||
page_servers.append(server)
|
page_servers.append(server)
|
||||||
|
un_used_servers.remove(server)
|
||||||
|
user_order.remove(server_id)
|
||||||
|
#we only want to set these server stats values once. We need to update the flag so it only hits that if once.
|
||||||
|
flag += 1
|
||||||
|
|
||||||
|
|
||||||
for server in page_data['servers']:
|
|
||||||
|
for server in un_used_servers:
|
||||||
server_ids.append(str(server['server_data']['server_id']))
|
server_ids.append(str(server['server_data']['server_id']))
|
||||||
if server not in page_servers:
|
if server not in page_servers:
|
||||||
page_servers.append(server)
|
page_servers.append(server)
|
||||||
for server_id in user_order:
|
for server_id in user_order:
|
||||||
#remove IDs in list that user no longer has access to
|
#remove IDs in list that user no longer has access to
|
||||||
if str(server_id) not in server_ids:
|
if str(server_id) not in server_ids[:]:
|
||||||
user_order.remove(server_id)
|
user_order.remove(server_id)
|
||||||
page_data['servers'] = page_servers
|
page_data['servers'] = page_servers
|
||||||
|
|
||||||
|
|
||||||
for data in page_data['servers']:
|
|
||||||
data['stats']['crashed'] = self.controller.servers.is_crashed(
|
|
||||||
str(data['stats']['server_id']['server_id']))
|
|
||||||
try:
|
|
||||||
data['stats']['waiting_start'] = self.controller.servers.get_waiting_start(
|
|
||||||
str(data['stats']['server_id']['server_id']))
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Failed to get server waiting to start: {e}")
|
|
||||||
data['stats']['waiting_start'] = False
|
|
||||||
|
|
||||||
|
|
||||||
for data in page_data['servers']:
|
|
||||||
data['stats']['crashed'] = self.controller.servers.is_crashed(
|
|
||||||
str(data['stats']['server_id']['server_id']))
|
|
||||||
try:
|
|
||||||
data['stats']['waiting_start'] = self.controller.servers.get_waiting_start(
|
|
||||||
str(data['stats']['server_id']['server_id']))
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Failed to get server waiting to start: {e}")
|
|
||||||
data['stats']['waiting_start'] = False
|
|
||||||
|
|
||||||
#num players is set to zero here. If we poll all servers while dashboard is loading it takes FOREVER. We leave this to the
|
#num players is set to zero here. If we poll all servers while dashboard is loading it takes FOREVER. We leave this to the
|
||||||
#async polling once dashboard is served.
|
#async polling once dashboard is served.
|
||||||
|
Loading…
Reference in New Issue
Block a user