mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-04 03:27:12 -05:00 
			
		
		
		
	Fix: Clear metadata cache when the filename(s) change (#5957)
* Update doc modified time upon move and rename * Clear the cached metadata if the filename(s) have been changed --------- Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									af16bb3934
								
							
						
					
					
						commit
						c57c1d5389
					
				@ -189,6 +189,11 @@ def refresh_metadata_cache(
 | 
				
			|||||||
    cache.touch(doc_key, timeout)
 | 
					    cache.touch(doc_key, timeout)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def clear_metadata_cache(document_id: int) -> None:
 | 
				
			||||||
 | 
					    doc_key = get_metadata_cache_key(document_id)
 | 
				
			||||||
 | 
					    cache.delete(doc_key)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_thumbnail_modified_key(document_id: int) -> str:
 | 
					def get_thumbnail_modified_key(document_id: int) -> str:
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    Builds the key to store a thumbnail's timestamp
 | 
					    Builds the key to store a thumbnail's timestamp
 | 
				
			||||||
 | 
				
			|||||||
@ -22,6 +22,7 @@ from django.utils import timezone
 | 
				
			|||||||
from filelock import FileLock
 | 
					from filelock import FileLock
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from documents import matching
 | 
					from documents import matching
 | 
				
			||||||
 | 
					from documents.caching import clear_metadata_cache
 | 
				
			||||||
from documents.classifier import DocumentClassifier
 | 
					from documents.classifier import DocumentClassifier
 | 
				
			||||||
from documents.consumer import parse_doc_title_w_placeholders
 | 
					from documents.consumer import parse_doc_title_w_placeholders
 | 
				
			||||||
from documents.file_handling import create_source_path_directory
 | 
					from documents.file_handling import create_source_path_directory
 | 
				
			||||||
@ -434,7 +435,9 @@ def update_filename_and_move_files(sender, instance: Document, **kwargs):
 | 
				
			|||||||
            Document.objects.filter(pk=instance.pk).update(
 | 
					            Document.objects.filter(pk=instance.pk).update(
 | 
				
			||||||
                filename=instance.filename,
 | 
					                filename=instance.filename,
 | 
				
			||||||
                archive_filename=instance.archive_filename,
 | 
					                archive_filename=instance.archive_filename,
 | 
				
			||||||
 | 
					                modified=timezone.now(),
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					            clear_metadata_cache(instance.pk)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        except (OSError, DatabaseError, CannotMoveFilesException) as e:
 | 
					        except (OSError, DatabaseError, CannotMoveFilesException) as e:
 | 
				
			||||||
            logger.warning(f"Exception during file handling: {e}")
 | 
					            logger.warning(f"Exception during file handling: {e}")
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user