| 115 | self._invalidate_app() |
| 116 | |
| 117 | def _run(self, schemas: list[str] | None) -> None: |
| 118 | executor: SQLExecute | None = None |
| 119 | try: |
| 120 | executor = self._make_executor() |
| 121 | except Exception as e: # pragma: no cover - defensive |
| 122 | _logger.error('schema prefetch could not open connection: %r', e) |
| 123 | self._invalidate_app() |
| 124 | return |
| 125 | try: |
| 126 | if schemas is None: |
| 127 | try: |
| 128 | schemas = list(executor.databases()) |
| 129 | except Exception as e: |
| 130 | _logger.error('failed to list databases for prefetch: %r', e) |
| 131 | return |
| 132 | current = self._current_schema() |
| 133 | existing = set(self.mycli.completer.dbmetadata.get('tables', {}).keys()) |
| 134 | queue = [s for s in schemas if s and s != current and s not in self._loaded and s not in existing] |
| 135 | for schema in queue: |
| 136 | if self._cancel.is_set(): |
| 137 | return |
| 138 | try: |
| 139 | self._prefetch_one(executor, schema) |
| 140 | self._loaded.add(schema) |
| 141 | except Exception as e: |
| 142 | _logger.error('prefetch failed for schema %r: %r', schema, e) |
| 143 | finally: |
| 144 | try: |
| 145 | executor.close() |
| 146 | except Exception: # pragma: no cover - defensive |
| 147 | pass |
| 148 | self._invalidate_app() |
| 149 | |
| 150 | def _prefetch_one(self, executor: SQLExecute, schema: str) -> None: |
| 151 | _logger.debug('prefetching schema %r', schema) |