Skip to content

Commit

Permalink
Use cached property for table migration index on local checkout conte…
Browse files Browse the repository at this point in the history
…xt (#3711)

## Changes

Use cached property for table migration index on local checkout context
to avoid multiple (re)crawling in case of an empty migration index

### Linked issues

Relates to #3687

### Functionality

- [x] modified existing command: `databricks labs ucx lint-local-code`

### Tests

- [x] manually tested
  • Loading branch information
JCZuurmond authored Feb 20, 2025
1 parent eb6009a commit 96913cc
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/databricks/labs/ucx/contexts/workspace_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from databricks.labs.ucx.hive_metastore.federation import HiveMetastoreFederation, HiveMetastoreFederationEnabler
from databricks.labs.ucx.hive_metastore.table_migration_status import TableMigrationIndex
from databricks.labs.ucx.progress.install import ProgressTrackingInstallation
from databricks.labs.ucx.source_code.base import CurrentSessionState
from databricks.labs.ucx.source_code.linters.context import LinterContext
from databricks.labs.ucx.source_code.linters.folders import LocalCodeLinter
from databricks.labs.ucx.source_code.notebooks.loaders import NotebookLoader
Expand Down Expand Up @@ -213,24 +212,22 @@ class LocalCheckoutContext(WorkspaceContext):
"""Local context extends Workspace context to provide extra properties
for running local operations."""

def linter_context_factory(self, session_state: CurrentSessionState | None = None):
@cached_property
def _migration_index(self) -> TableMigrationIndex:
try:
index = self.tables_migrator.index()
except NotFound:
logger.warning("Metastore does not seem to exist yet. Skipping loading of migration status.")
index = TableMigrationIndex([])
if session_state is None:
session_state = CurrentSessionState()
return LinterContext(index, session_state)
return index

@cached_property
def local_code_linter(self) -> LocalCodeLinter:
session_state = CurrentSessionState()
return LocalCodeLinter(
self.notebook_loader,
self.file_loader,
self.folder_loader,
self.path_lookup,
self.dependency_resolver,
lambda: self.linter_context_factory(session_state),
lambda: LinterContext(self._migration_index),
)

0 comments on commit 96913cc

Please sign in to comment.