Skip to content

Commit

Permalink
Initialize workflow tables from file cache
Browse files Browse the repository at this point in the history
  • Loading branch information
gizmo385 committed Dec 29, 2024
1 parent 4ad8f8e commit b7fc1d3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions lazy_github/ui/screens/primary.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ async def load_repository(self, repo: Repository) -> None:
self.issues.load_cached_issues_for_current_repo()
self.fetch_issues_and_pull_requests(repo)
if self.workflows.display:
self.workflows.initialize_tables_from_cache()
self.workflows.load_repo(repo)

@on(RepoSelected)
Expand Down
22 changes: 18 additions & 4 deletions lazy_github/ui/widgets/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ async def action_trigger_workflow(self) -> None:


class WorkflowRunsContainer(Container):
workflow_runs: dict[int, WorkflowRun] = {}

def compose(self) -> ComposeResult:
yield LazilyLoadedDataTable(
id="searchable_workflow_runs_table",
Expand All @@ -97,6 +95,7 @@ def compose(self) -> ComposeResult:
batch_size=30,
item_to_row=workflow_run_to_cell,
item_to_key=lambda wr: str(wr.run_number),
cache_name="workflow_runs",
reverse_sort=True,
)

Expand All @@ -115,6 +114,9 @@ def on_mount(self) -> None:
self.table.add_column("Job Name", key="job_name")
self.table.add_column("Run Name", key="run_name")

def load_cached_workflow_runs(self) -> None:
self.searchable_table.initialize_from_cache(WorkflowRun)

async def fetch_more_workflow_runs(
self, repo: Repository, batch_size: int, batch_to_fetch: int
) -> list[WorkflowRun]:
Expand All @@ -139,7 +141,19 @@ def compose(self) -> ComposeResult:
with TabPane("Workflows", id="workflows_tab"):
yield AvailableWorkflowsContainers(id="workflows")

@property
def workflows(self) -> AvailableWorkflowsContainers:
return self.query_one("#workflows", AvailableWorkflowsContainers)

@property
def workflow_runs(self) -> WorkflowRunsContainer:
return self.query_one("#workflow_runs", WorkflowRunsContainer)

def initialize_tables_from_cache(self) -> None:
self.workflows.load_cached_workflows()
self.workflow_runs.load_cached_workflow_runs()

@work
async def load_repo(self, repo: Repository) -> None:
await self.query_one("#workflows", AvailableWorkflowsContainers).load_repo(repo)
await self.query_one("#workflow_runs", WorkflowRunsContainer).load_repo(repo)
await self.workflows.load_repo(repo)
await self.workflow_runs.load_repo(repo)

0 comments on commit b7fc1d3

Please sign in to comment.