Spaces:
Sleeping
Sleeping
Commit
·
89f16da
1
Parent(s):
95dc3cb
likes
Browse files- app.py +23 -8
- templates/dashboard.html +1 -1
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import sqlite3
|
|
| 5 |
import json
|
| 6 |
import time
|
| 7 |
from datetime import datetime, timezone
|
|
|
|
| 8 |
from flask import Flask, redirect, request, session, render_template, url_for, g
|
| 9 |
import requests
|
| 10 |
|
|
@@ -128,15 +129,29 @@ def fetch_user_spaces(username, token=None):
|
|
| 128 |
resp = requests.get(url, headers=headers, timeout=10)
|
| 129 |
if resp.status_code == 200:
|
| 130 |
space_list = resp.json()
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
for space in space_list:
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
else:
|
| 139 |
-
spaces.append(space)
|
| 140 |
except Exception:
|
| 141 |
pass
|
| 142 |
|
|
|
|
| 5 |
import json
|
| 6 |
import time
|
| 7 |
from datetime import datetime, timezone
|
| 8 |
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 9 |
from flask import Flask, redirect, request, session, render_template, url_for, g
|
| 10 |
import requests
|
| 11 |
|
|
|
|
| 129 |
resp = requests.get(url, headers=headers, timeout=10)
|
| 130 |
if resp.status_code == 200:
|
| 131 |
space_list = resp.json()
|
| 132 |
+
space_ids = [s.get("id", "") for s in space_list if s.get("id")]
|
| 133 |
+
|
| 134 |
+
# Fetch individual space details in parallel
|
| 135 |
+
with ThreadPoolExecutor(max_workers=10) as executor:
|
| 136 |
+
future_to_id = {
|
| 137 |
+
executor.submit(fetch_space_detail, sid, token): sid
|
| 138 |
+
for sid in space_ids
|
| 139 |
+
}
|
| 140 |
+
details_map = {}
|
| 141 |
+
for future in as_completed(future_to_id):
|
| 142 |
+
sid = future_to_id[future]
|
| 143 |
+
try:
|
| 144 |
+
details_map[sid] = future.result()
|
| 145 |
+
except Exception:
|
| 146 |
+
details_map[sid] = None
|
| 147 |
+
|
| 148 |
+
# Build list and sort by likes
|
| 149 |
for space in space_list:
|
| 150 |
+
sid = space.get("id", "")
|
| 151 |
+
detail = details_map.get(sid)
|
| 152 |
+
spaces.append(detail if detail else space)
|
| 153 |
+
|
| 154 |
+
spaces.sort(key=lambda x: x.get("likes", 0), reverse=True)
|
|
|
|
|
|
|
| 155 |
except Exception:
|
| 156 |
pass
|
| 157 |
|
templates/dashboard.html
CHANGED
|
@@ -388,7 +388,7 @@
|
|
| 388 |
{% set storage = space.runtime.storage.current|default('none') if space.runtime and space.runtime.storage else 'none' %}
|
| 389 |
<div class="space-entry">
|
| 390 |
<div class="space-item space-toggle" data-space="{{ loop.index }}">
|
| 391 |
-
<span class="space-name">{{ space.id.split('/')[-1] }}</span>
|
| 392 |
<span class="space-status {{ status|lower }}">
|
| 393 |
{% if status == 'RUNNING' %}running
|
| 394 |
{% elif status == 'BUILDING' %}building
|
|
|
|
| 388 |
{% set storage = space.runtime.storage.current|default('none') if space.runtime and space.runtime.storage else 'none' %}
|
| 389 |
<div class="space-entry">
|
| 390 |
<div class="space-item space-toggle" data-space="{{ loop.index }}">
|
| 391 |
+
<span class="space-name">{{ space.id.split('/')[-1] }} <span style="color:#444;font-size:0.6875rem;">{{ space.likes|default(0) }}</span></span>
|
| 392 |
<span class="space-status {{ status|lower }}">
|
| 393 |
{% if status == 'RUNNING' %}running
|
| 394 |
{% elif status == 'BUILDING' %}building
|