def delete_thumbnails(self, md5_names: List[str]) -> None: """ Deletes thumbnails from SQL cache :param md5_names: list of names, without path """ if len(md5_names) == 0: return conn = sqlite3.connect(self.db) # Limit to number of parameters: 900 # See https://www.sqlite.org/limits.html try: if len(md5_names) > 900: name_chunks = divide_list_on_length(md5_names, 900) for chunk in name_chunks: self._delete(chunk, conn) else: self._delete(md5_names, conn) except sqlite3.OperationalError as e: logging.error("Database error while deleting %s thumbnails: %s", len(md5_names), e) else: conn.commit() conn.close()
def _set_list_values(self, uids: List[bytes], update_value, value) -> None: if len(uids) == 0: return # Limit to number of parameters: 900 # See https://www.sqlite.org/limits.html if len(uids) > 900: uid_chunks = divide_list_on_length(uids, 900) for chunk in uid_chunks: update_value(chunk, value) else: update_value(uids, value) self.conn.commit()
def any_not_previously_downloaded(self, uids: List[bytes]) -> bool: """ :param uids: list of UIDs to check :return: True if any of the files associated with the UIDs have not been previously downloaded """ if len(uids) > 900: uid_chunks = divide_list_on_length(uids, 900) for chunk in uid_chunks: if self._any_not_previously_downloaded(uids=uid_chunks): return True return False else: return self._any_not_previously_downloaded(uids=uids)
def set_job_code_assigned(self, uids: List[bytes], job_code: bool) -> None: if len(uids) == 1: query = 'UPDATE files SET job_code=? WHERE uid=?' # logging.debug('%s (%s, <uid>)', query, job_code) self.conn.execute(query, (job_code, uids[0])) else: # Limit to number of parameters: 900 # See https://www.sqlite.org/limits.html if len(uids) > 900: name_chunks = divide_list_on_length(uids, 900) for chunk in name_chunks: self._mass_set_job_code_assigned(chunk, job_code) else: self._mass_set_job_code_assigned(uids, job_code) self.conn.commit()
def delete_uids(self, uids: List[bytes]) -> None: """ Deletes thumbnails from SQL cache :param uids: list of uids to delete """ if len(uids) == 0: return # Limit to number of parameters: 900 # See https://www.sqlite.org/limits.html if len(uids) > 900: name_chunks = divide_list_on_length(uids, 900) for chunk in name_chunks: self._delete_uids(chunk) else: self._delete_uids(uids) self.conn.commit()