1717from tagstudio .core .library .alchemy .models import Entry
1818from tagstudio .core .library .ignore import PATH_GLOB_FLAGS , Ignore , ignore_to_glob
1919from tagstudio .core .utils .silent_subprocess import silent_run # pyright: ignore
20+ from tagstudio .core .utils .types import unwrap
2021
2122logger = structlog .get_logger (__name__ )
2223
@@ -30,24 +31,27 @@ class RefreshTracker:
3031 def files_count (self ) -> int :
3132 return len (self .files_not_in_library )
3233
33- def save_new_files (self ):
34+ def save_new_files (self ) -> Iterator [ int ] :
3435 """Save the list of files that are not in the library."""
35- if self .files_not_in_library :
36+ batch_size = 200
37+
38+ index = 0
39+ while index < len (self .files_not_in_library ):
40+ yield index
41+ end = min (len (self .files_not_in_library ), index + batch_size )
3642 entries = [
3743 Entry (
3844 path = entry_path ,
39- folder = self .library .folder , # pyright: ignore[reportArgumentType]
45+ folder = unwrap ( self .library .folder ),
4046 fields = [],
4147 date_added = dt .now (),
4248 )
43- for entry_path in self .files_not_in_library
49+ for entry_path in self .files_not_in_library [ index : end ]
4450 ]
4551 self .library .add_entries (entries )
46-
52+ index = end
4753 self .files_not_in_library = []
4854
49- yield
50-
5155 def refresh_dir (self , library_dir : Path , force_internal_tools : bool = False ) -> Iterator [int ]:
5256 """Scan a directory for files, and add those relative filenames to internal variables.
5357
0 commit comments