()
| 855 | return result |
| 856 | |
| 857 | |
| 858 | _ENV_FILE_CACHE_LOCK = threading.Lock() |
| 859 | # (mtime_ns, size) -> parsed .env contents. Every _env_text() lookup used to |
| 860 | # re-read and re-parse .env from disk, and settings-derived paths are consulted |
| 861 | # per file while scanning reports: 23718 reads of the same file for a single |
| 862 | # reports refresh, which dominated the runtime. Keyed on mtime+size so an edit |
| 863 | # through the settings panel is still picked up immediately. |
| 864 | _ENV_FILE_CACHE: Optional[Tuple[int, int, Dict[str, str]]] = None |
| 865 | |
| 866 | |
| 867 | def _read_env_file() -> Dict[str, str]: |
| 868 | global _ENV_FILE_CACHE |
| 869 | try: |
| 870 | stat = ENV_PATH.stat() |
| 871 | signature = (stat.st_mtime_ns, stat.st_size) |
| 872 | except OSError: |
| 873 | # No .env at all: nothing to cache, and callers fall back to os.environ. |
| 874 | with _ENV_FILE_CACHE_LOCK: |
| 875 | _ENV_FILE_CACHE = None |
no test coverage detected