xiaolongmr commited on
Commit
cca328f
·
1 Parent(s): 0e43c63

Prime shared announcements on startup

Browse files
Files changed (1) hide show
  1. services/config.py +10 -0
services/config.py CHANGED
@@ -244,6 +244,7 @@ class ConfigStore:
244
  "2. 或者在 config.json 中填写:\n"
245
  ' "auth-key": "your_real_auth_key"'
246
  )
 
247
 
248
  def _load(self) -> dict[str, object]:
249
  return _read_json_object(self.path, name="config.json")
@@ -494,9 +495,18 @@ class ConfigStore:
494
  if isinstance(state, dict) and "items" in state:
495
  return shared_items
496
  if local_items:
 
497
  self._save_shared_announcements(local_items)
498
  return local_items
499
 
 
 
 
 
 
 
 
 
500
  def _save_shared_announcements(self, items: list[dict[str, object]]) -> list[dict[str, object]]:
501
  normalized = _normalize_announcements(items)
502
  storage = self._shared_announcements_storage()
 
244
  "2. 或者在 config.json 中填写:\n"
245
  ' "auth-key": "your_real_auth_key"'
246
  )
247
+ self._prime_shared_announcements()
248
 
249
  def _load(self) -> dict[str, object]:
250
  return _read_json_object(self.path, name="config.json")
 
495
  if isinstance(state, dict) and "items" in state:
496
  return shared_items
497
  if local_items:
498
+ print(f"[announcements] Migrating local announcements to shared storage: {len(local_items)} items")
499
  self._save_shared_announcements(local_items)
500
  return local_items
501
 
502
+ def _prime_shared_announcements(self) -> None:
503
+ if not os.getenv("SHARED_USER_DATABASE_URL", "").strip():
504
+ return
505
+ try:
506
+ self._load_announcements()
507
+ except Exception as exc:
508
+ print(f"[announcements] prime shared announcements failed: {exc}")
509
+
510
  def _save_shared_announcements(self, items: list[dict[str, object]]) -> list[dict[str, object]]:
511
  normalized = _normalize_announcements(items)
512
  storage = self._shared_announcements_storage()