Skip to content

Commit 3b079e4

Browse files
author
piotrj
committed
garbage collector activated manually in critical sections, search optimizations
1 parent dddc4c4 commit 3b079e4

File tree

3 files changed

+111
-46
lines changed

3 files changed

+111
-46
lines changed

src/core.py

+36-26
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
windows = bool(os_name=='nt')
3737

3838
if windows:
39-
from subprocess import CREATE_NO_WINDOW,HIGH_PRIORITY_CLASS
39+
from subprocess import CREATE_NO_WINDOW
4040
else:
4141
from os import getpgid, killpg
4242

@@ -217,20 +217,16 @@ def kill_subprocess(subproc):
217217
except Exception as ke:
218218
print(f'kill_subprocess: {ke}')
219219

220-
def compress_with_stats(data,compression):
220+
def compress_with_header_update(header,data,compression,datalabel,zip_file):
221221
t0 = perf_counter()
222222
data_ser = dumps(data)
223223
data_ser_compr = ZstdCompressor(level=compression,threads=-1).compress(data_ser)
224224
t1 = perf_counter()
225225
tdiff=t1-t0
226226

227-
return data_ser_compr,tdiff,asizeof(data_ser_compr),asizeof(data_ser),asizeof(data)
228-
229-
def compress_with_header_update(header,data,compression,datalabel,zip_file):
230-
data_compr,tdiff,size_1,size_2,size_3 = compress_with_stats(data,compression)
231-
header.zipinfo[datalabel]=(size_1,size_2,size_3)
232-
header.compression_time[datalabel] = tdiff
233-
zip_file.writestr(datalabel,data_compr)
227+
header.zipinfo[datalabel]=(asizeof(data_ser_compr),asizeof(data_ser),asizeof(data))
228+
header.compression_time[datalabel] = tdiff
229+
zip_file.writestr(datalabel,data_ser_compr)
234230

235231
CREATION_CODE = 0
236232
EXPORT_CODE = 1
@@ -848,7 +844,8 @@ def find_items(self,
848844
size_min,size_max,
849845
timestamp_min,timestamp_max,
850846
name_search_kind,name_func_to_call,
851-
cd_search_kind,cd_func_to_call):
847+
cd_search_kind,cd_func_to_call,
848+
print_info_fn):
852849

853850
self.find_results = []
854851

@@ -872,7 +869,7 @@ def find_items(self,
872869
search_list_pop = search_list.pop
873870
search_list_append = search_list.append
874871

875-
cd_search_kind_is_regezp_glob_or_fuzzy = bool(cd_search_kind in ('regexp','glob','fuzzy'))
872+
cd_search_kind_is_regexp_glob_or_fuzzy = bool(cd_search_kind in ('regexp','glob','fuzzy'))
876873
cd_search_kind_is_dont_or_without = bool(cd_search_kind in ('dont','without'))
877874

878875
when_folder_may_apply = bool(cd_search_kind_is_dont_or_without and not use_size and not use_timestamp)
@@ -893,11 +890,6 @@ def find_items(self,
893890
#if check_abort():
894891
# break
895892

896-
search_progress_update_quant+=1
897-
if search_progress_update_quant>1024:
898-
results_queue_put([search_progress])
899-
search_progress_update_quant=0
900-
901893
search_progress +=1
902894

903895
name_nr,code,size,mtime = data_entry[0:4]
@@ -961,7 +953,7 @@ def find_items(self,
961953
if not name_func_to_call(name):
962954
continue
963955
except Exception as e:
964-
self.log.error('find_items(1):%s',str(e) )
956+
print_info_fn(f'find_items(1):{e}' )
965957
continue
966958

967959
#oczywistosc
@@ -971,18 +963,27 @@ def find_items(self,
971963
if cd_search_kind_is_any:
972964
if not has_cd or not cd_ok:
973965
continue
974-
elif cd_search_kind_is_regezp_glob_or_fuzzy:
966+
elif cd_search_kind_is_regexp_glob_or_fuzzy:
975967
if has_cd and cd_ok:
976968
cd_data = self_customdata[cd_nr][2]
977969
else:
978970
continue
979971

980972
if cd_func_to_call:
981973
try:
982-
if not cd_func_to_call(cd_data):
983-
continue
974+
if True: #entire file
975+
if not cd_func_to_call(cd_data):
976+
continue
977+
else:
978+
found=False
979+
for line in cd_data.splitlines():
980+
if cd_func_to_call(line):
981+
found=True
982+
break
983+
if not found:
984+
continue
984985
except Exception as e:
985-
self.log.error('find_items(2):%s',str(e) )
986+
print_info_fn(f'find_items(2):{e}' )
986987
continue
987988

988989
else:
@@ -1000,6 +1001,12 @@ def find_items(self,
10001001
results_queue_put([search_progress,size,mtime,*next_level])
10011002
search_progress_update_quant=0
10021003

1004+
if search_progress_update_quant>1024:
1005+
results_queue_put([search_progress])
1006+
search_progress_update_quant=0
1007+
else:
1008+
search_progress_update_quant+=1
1009+
10031010
results_queue_put([search_progress])
10041011
results_queue_put(True)
10051012

@@ -1345,6 +1352,7 @@ def repack_record(self,record,new_label,new_compression,keep_cd,update_callback)
13451352
messages = []
13461353

13471354
new_file_path = sep.join([self.db_dir,f'rep.{int(time())}.dat'])
1355+
13481356
try:
13491357
src_file = record.file_path
13501358

@@ -1470,7 +1478,7 @@ def find_items_in_records_check(self,
14701478
filename_fuzzy_threshold,cd_fuzzy_threshold):
14711479

14721480
sel_range = [range_par] if range_par else self.records
1473-
self.files_search_quant = sum([record.header.quant_files for record in sel_range])
1481+
self.files_search_quant = sum([record.header.quant_files+record.header.quant_folders for record in sel_range])
14741482

14751483
if self.files_search_quant==0:
14761484
return 1
@@ -1530,14 +1538,16 @@ def find_items_in_records(self,
15301538
records_to_process.sort(reverse = True,key = lambda x : x.header.quant_files)
15311539

15321540
record_commnad_list={}
1541+
is_frozen = bool(getattr(sys, 'frozen', False))
1542+
15331543
for record_nr,record in enumerate(records_to_process):
15341544
if windows:
1535-
if getattr(sys, 'frozen', False):
1545+
if is_frozen:
15361546
curr_command_list = record_commnad_list[record_nr] = ['record.exe', 'load',record.file_path]
15371547
else:
15381548
curr_command_list = record_commnad_list[record_nr] = ['python','src\\record.py', 'load',record.file_path]
15391549
else:
1540-
if getattr(sys, 'frozen', False):
1550+
if is_frozen:
15411551
curr_command_list = record_commnad_list[record_nr] = ['./record', 'load',record.file_path]
15421552
else:
15431553
curr_command_list = record_commnad_list[record_nr] = ['python3','./src/record.py', 'load',record.file_path]
@@ -1628,8 +1638,8 @@ def threaded_run(record_nr,commands_list,results_list,progress_list,info_list,pr
16281638
else:
16291639
info_list[record_nr].append(line.strip())
16301640
except Exception as e:
1631-
print('threaded_run work error:',e,line)
1632-
info_list[record_nr].append(f'threaded_run work error: {e} line: {line}')
1641+
print(f'threaded_run work error:{e} line:{line}')
1642+
info_list[record_nr].append(f'threaded_run work error:{e} line:{line}')
16331643
else:
16341644
if subprocess_poll() is not None:
16351645
break

0 commit comments

Comments
 (0)