helgeerbe / picframe

Picture frame viewer for raspi, controlled via mqtt and automatticly integrated as mqtt device in homeassistant.
MIT License
110 stars 32 forks source link

Minor bug in __update_folder_info in module image_cache.py #317

Open greensum opened 1 year ago

greensum commented 1 year ago

I have some folders that contain only sub-folders and no image files. I found these folders are always treated as new folders and get scanned again and again. I think the bug is in def __update_folder_info. There we only do an "UPDATE" without an "INSERT" like when we are dealing with image files.

I made the following changes by following the treatment of files and it seems to fix the problem.

    def __update_folder_info(self, folder_collection):
        if not folder_collection: return # **ADDED**
        update_data = []
        insert_data = [] # **ADDED**
        sql_insert = "INSERT OR IGNORE INTO folder(name) VALUES(?)" # **ADDED**
        sql = "UPDATE folder SET last_modified = ?, missing = 0 WHERE name = ?"
        for folder, modtime in folder_collection:
            update_data.append((modtime, folder))
            insert_data.append((folder,)) # **ADDED**
        self.__db_write_lock.acquire()
        self.__db.executemany(sql_insert, insert_data) # **ADDED**
        self.__db.executemany(sql, update_data)
        self.__db_write_lock.release()

Please verify if that's the right fix. Thanks for all the great work! Vincent.

helgeerbe commented 1 year ago

Hi @greensum ,

Thanks for reporting. I will check this.