- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 228
Asset cache reworked #1559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Draft
      
      
            QubaB
  wants to merge
  35
  commits into
  saber-notes:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
QubaB:AssetChacheReworked
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
                
     Draft
            
            Asset cache reworked #1559
Conversation
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
    …time and removes all duplicities Now implemented only adding to cache during read of note fromJson. Calculated is previewHash from first 100kB of files for fast recognition of assets which are duplicated (all assets which are saved after note is reedited)
…ages as single object started implementation of lazy ImageProvider
…hare the same asset only one image provider is used replaceImage is implemented when png image is resized due to its greater size
important is add $documentsDirectory to file name otherwise assets are saved to root of file system and it is not allowed
…can be used to recognize the same pdf files instead of calculating hash of all file contents class parse linearized and normal pdfs.
svg files are not handled
…rovider when asset filename is changed
…ve so after writing note only markFileAsSaved is called to upload items, ...
…ase speed of loading assets
…rer. It will later allow to change notifier when asset filename will change
…h on PdfDocument.OpenFile
…older. It allows fast rename of file during saving note and skipping unused assets_test at the end of Editor is temporary directory deleted. to compare correctly filename paths fixFileNameDelimiters is called.
…ermine number of pdf pages and their size. Instead it waits for opening pdfDocument. Printing.raster caused Saber crash on windows. This method is fast.
…fixed adding assets using addSync when order of assets is not correct.
…round pdfs are read last)
…se FileManager in isolate (when reading large notes on background).
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
      
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
I prepared draft of assetCache upgrade, it works and is able to read already saved notes and also save newly created notes. I would like if someone test it. I tested it on Windows and Android and seems to work correctly.
Current implementation of assetCache, especially handling pdf files does not work correctly.
My code is not very polished, and it contains several unnecessary and inelegant parts (as I am not highly experienced in programming asynchronous applications). However, I hope it may serve as a useful starting point for considering how to adapt the current cache to ensure it functions correctly and efficiently with PDF files.
I also tried to ensure that notes created in the current version of Saber can be loaded. When reloading a note that contains a PDF and then saving it again, an asset is created for each page, each containing the entire PDF. This is why AssetCacheAll.addSync is particularly complicated and makes use of previewHash to identify many identical files using starting 100KB bytes and file size.
I tested this implementation on windows and Android (Samsung Galaxy Tab A7 lite). Both were able to display 850 pages pdf and note was loaded quite fast and pages are displayed almost instantly during listing pages.
Short description of current state of cache and my approach follows
Current cache and images problems:
New approach to cache
Cache handles jpg, png, pdf, svg. All cache items are File.
For each photo item provides ValueNotifier<ImageProvider?>, so the same items have the same ImageProvider.
For each pdf item provides ValueNotifier<PdfDocument?>, so every page of pdf use the same provider.
During the reading of note to Editor are new items added using addSync - which is fast and synchronous
addSync method:
In Editor is used async method when adding new image
add method:
it compares first paths, file size and then hashes of all cache items
calculation of hash is very time consuming, it will be better for pdfs to extract /Info and read author, creation date, etc.
and use this to recognize different pdfs. It will take less time.
Cache properties:
When note is saved and some image is removed from note, asset files are reordered. If it happens their image of pdf providers must be changed. Especially pdf pages disappear for a while until new pdfDocument is opened - it can be solved, but I did not care now.
I believe the cache needs to be rewritten, as many users work with PDFs and the current version is not functional and cannot handle displaying PDFs with hundreds of pages.