|
23 | 23 | from .merginproject import MerginProject |
24 | 24 | from .editor import filter_changes |
25 | 25 |
|
| 26 | +def _do_upload(item, job): |
| 27 | + """runs in worker thread, have to be defined here to avoid worker threads repeating this function""" |
| 28 | + if job.is_cancelled: |
| 29 | + return |
| 30 | + |
| 31 | + item.upload_blocking() |
| 32 | + job.transferred_size += item.size |
| 33 | + |
26 | 34 |
|
27 | 35 | class UploadChunksCache: |
28 | 36 | """A cache for uploaded chunks to avoid re-uploading them, using checksum as key.""" |
@@ -101,14 +109,12 @@ def upload_blocking(self): |
101 | 109 | checksum_str = checksum.hexdigest() |
102 | 110 |
|
103 | 111 | self.mp.log.debug(f"Uploading {self.file_path} part={self.chunk_index}") |
104 | | - |
105 | 112 | if self.mc.server_features().get("v2_push_enabled"): |
106 | 113 | # use v2 API for uploading chunks |
107 | 114 | self.upload_chunk_v2_api(data, checksum_str) |
108 | 115 | else: |
109 | 116 | # use v1 API for uploading chunks |
110 | 117 | self.upload_chunk(data, checksum_str) |
111 | | - self.mc.upload_chunks_cache.add(checksum_str, self.chunk_id) |
112 | 118 |
|
113 | 119 | self.mp.log.debug(f"Upload chunk finished: {self.file_path}") |
114 | 120 |
|
@@ -138,17 +144,10 @@ def dump(self): |
138 | 144 | print("- {} {} {}".format(item.file_path, item.chunk_index, item.size)) |
139 | 145 | print("--- END ---") |
140 | 146 |
|
141 | | - def __upload_item(self, item: UploadQueueItem): |
142 | | - """Upload a single item in the background""" |
143 | | - if self.is_cancelled: |
144 | | - return |
145 | | - |
146 | | - item.upload_blocking() |
147 | | - self.transferred_size += item.size |
148 | 147 |
|
149 | 148 | def submit_item_to_thread(self, item: UploadQueueItem): |
150 | 149 | """Upload a single item in the background""" |
151 | | - feature = self.executor.submit(self.__upload_item, item) |
| 150 | + feature = self.executor.submit(_do_upload, item, self) |
152 | 151 | self.futures.append(feature) |
153 | 152 |
|
154 | 153 | def add_items(self, items: List[UploadQueueItem], total_size: int): |
|
0 commit comments