Spaces:
Running
Running
Upload storage.py
Browse files- storage.py +17 -5
storage.py
CHANGED
|
@@ -90,12 +90,15 @@ def load_wall_posts() -> list:
|
|
| 90 |
return _load_json(LOCAL_WALL_FILE, [])
|
| 91 |
|
| 92 |
def save_wall_posts(posts: list) -> bool:
|
| 93 |
-
"""Save wall posts to local file and sync to HF dataset."""
|
| 94 |
with _lock:
|
| 95 |
ok = _save_json(LOCAL_WALL_FILE, posts[:200]) # Keep max 200
|
| 96 |
if ok:
|
| 97 |
# Async upload to HF dataset
|
| 98 |
-
threading.Thread(
|
|
|
|
|
|
|
|
|
|
| 99 |
return ok
|
| 100 |
|
| 101 |
# ===== Interactions =====
|
|
@@ -107,7 +110,10 @@ def save_interactions(data: dict) -> bool:
|
|
| 107 |
with _lock:
|
| 108 |
ok = _save_json(LOCAL_INTERACTIONS_FILE, data)
|
| 109 |
if ok:
|
| 110 |
-
threading.Thread(
|
|
|
|
|
|
|
|
|
|
| 111 |
return ok
|
| 112 |
|
| 113 |
# ===== Comments =====
|
|
@@ -119,7 +125,10 @@ def save_comments(data: dict) -> bool:
|
|
| 119 |
with _lock:
|
| 120 |
ok = _save_json(LOCAL_COMMENTS_FILE, data)
|
| 121 |
if ok:
|
| 122 |
-
threading.Thread(
|
|
|
|
|
|
|
|
|
|
| 123 |
return ok
|
| 124 |
|
| 125 |
# ===== Shorts Cache =====
|
|
@@ -131,7 +140,10 @@ def save_shorts_cache(data: dict) -> bool:
|
|
| 131 |
with _lock:
|
| 132 |
ok = _save_json(LOCAL_SHORTS_CACHE, data)
|
| 133 |
if ok:
|
| 134 |
-
threading.Thread(
|
|
|
|
|
|
|
|
|
|
| 135 |
return ok
|
| 136 |
|
| 137 |
# Auto-sync on startup
|
|
|
|
| 90 |
return _load_json(LOCAL_WALL_FILE, [])
|
| 91 |
|
| 92 |
def save_wall_posts(posts: list) -> bool:
|
| 93 |
+
"""Save wall posts to local file and async sync to HF dataset."""
|
| 94 |
with _lock:
|
| 95 |
ok = _save_json(LOCAL_WALL_FILE, posts[:200]) # Keep max 200
|
| 96 |
if ok:
|
| 97 |
# Async upload to HF dataset
|
| 98 |
+
threading.Thread(
|
| 99 |
+
target=lambda: _upload_file(LOCAL_WALL_FILE, "wall_posts.json"),
|
| 100 |
+
daemon=True
|
| 101 |
+
).start()
|
| 102 |
return ok
|
| 103 |
|
| 104 |
# ===== Interactions =====
|
|
|
|
| 110 |
with _lock:
|
| 111 |
ok = _save_json(LOCAL_INTERACTIONS_FILE, data)
|
| 112 |
if ok:
|
| 113 |
+
threading.Thread(
|
| 114 |
+
target=lambda: _upload_file(LOCAL_INTERACTIONS_FILE, "interactions_v2.json"),
|
| 115 |
+
daemon=True
|
| 116 |
+
).start()
|
| 117 |
return ok
|
| 118 |
|
| 119 |
# ===== Comments =====
|
|
|
|
| 125 |
with _lock:
|
| 126 |
ok = _save_json(LOCAL_COMMENTS_FILE, data)
|
| 127 |
if ok:
|
| 128 |
+
threading.Thread(
|
| 129 |
+
target=lambda: _upload_file(LOCAL_COMMENTS_FILE, "comments_v2.json"),
|
| 130 |
+
daemon=True
|
| 131 |
+
).start()
|
| 132 |
return ok
|
| 133 |
|
| 134 |
# ===== Shorts Cache =====
|
|
|
|
| 140 |
with _lock:
|
| 141 |
ok = _save_json(LOCAL_SHORTS_CACHE, data)
|
| 142 |
if ok:
|
| 143 |
+
threading.Thread(
|
| 144 |
+
target=lambda: _upload_file(LOCAL_SHORTS_CACHE, "shorts_cache.json"),
|
| 145 |
+
daemon=True
|
| 146 |
+
).start()
|
| 147 |
return ok
|
| 148 |
|
| 149 |
# Auto-sync on startup
|