加载配置到内存缓存
(self)
| 199 | log.error(f"Error ensuring schema compatibility: {e}") |
| 200 | |
| 201 | async def _load_config_cache(self) -> None: |
| 202 | """加载配置到内存缓存""" |
| 203 | if self._config_loaded: |
| 204 | return |
| 205 | |
| 206 | try: |
| 207 | async with self._pool.acquire() as conn: |
| 208 | rows = await conn.fetch("SELECT key, value FROM config") |
| 209 | |
| 210 | for row in rows: |
| 211 | try: |
| 212 | self._config_cache[row["key"]] = json.loads(row["value"]) |
| 213 | except json.JSONDecodeError: |
| 214 | self._config_cache[row["key"]] = row["value"] |
| 215 | |
| 216 | self._config_loaded = True |
| 217 | log.debug(f"Loaded {len(self._config_cache)} config items into cache") |
| 218 | |
| 219 | except Exception as e: |
| 220 | log.error(f"Error loading config cache: {e}") |
| 221 | self._config_cache = {} |
| 222 | |
| 223 | async def close(self) -> None: |
| 224 | """关闭数据库连接池""" |
no test coverage detected