Skip to content

Commit 9ce6502

Browse files
committed
perf(metadata):cache reading of frequently-accesses lists
1 parent 3e2cbdd commit 9ce6502

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/ZooProcess_lib/ZooscanFolder.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import re
33
from datetime import datetime
4+
from functools import lru_cache
45
from os import DirEntry
56
from pathlib import Path
67
from typing import List, Tuple, Union, Dict, TypedDict, Optional, Generator
@@ -72,6 +73,9 @@ def list_samples_with_state(self) -> list[str]:
7273
except (FileNotFoundError, KeyError):
7374
return []
7475

76+
@lru_cache(
77+
maxsize=1
78+
) # For speed. TODO: A dedicated primitive, with _real_ state, i.e. progress in workflow of the scan
7579
def list_scans_with_state(self) -> Generator[str, None, None]:
7680
"""Inventory done using:
7781
zooscan_lov/Zooscan_apero_tha_bioness_2_sn033$ find . -name "apero2023_tha_bioness_013_st46_d_n4_d2_2_sur_2*" | sort

src/ZooProcess_lib/tools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import sys
44
import time
5+
from functools import lru_cache
56
from pathlib import Path
67
from typing import Callable, Any, Tuple, List, Dict
78

@@ -72,9 +73,9 @@ def create_folder(path: Path):
7273
eprint("cannot create folder: ", path_str, ", ", str(error))
7374

7475

76+
@lru_cache(maxsize=2) # Keep last sample and last scan
7577
def parse_csv(file_path: Path) -> List[Dict[str, str]]:
7678
"""Parses a CSV file and returns a list of dictionaries."""
77-
7879
data: List[Dict[str, str]] = []
7980
with open(file_path, "r", newline="", encoding="ISO-8859-1") as csv_file:
8081
reader = csv.DictReader(csv_file, delimiter=";")

0 commit comments

Comments
 (0)