| 
			
			 | 
		#1 | 
| 
			
			
			
			 want to learn what I want 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,682 
				Karma: 7908443 
				Join Date: Sep 2020 
				
				
				
				Device: none 
				
				
				 | 
	
	
	
		
		
			
			 
				
				Last annotation date
			 
			
			
			Hi, 
		
	
		
		
		
		
		
		
		
		
		
		
	
	I'm running an Action Chain that filters a custom column with annotation count:true, then selects a View Manager preset that sorts the list by Last Action Date (from Last Modified plugin). This should give me in Library View a list of recently annotated titles in Calibre viewer. However, as the Last Action column is also updated by other db changes, I thought of adding a custom column to display a book's last annotation date. From looking at db\cache.py, I take it this might be possible... Code: 
	@write_api
    def merge_annotations_for_book(self, book_id, fmt, annots_list, user_type='local', user='viewer'):
        '''
        Merge the specified annotations into the existing annotations for book_id, fm, user_type, and user.
        '''
        from calibre.utils.date import EPOCH
        from calibre.utils.iso8601 import parse_iso8601
        amap = self._annotations_map_for_book(book_id, fmt, user_type=user_type, user=user)
        merge_annotations(annots_list, amap)
        alist = []
        for val in itervalues(amap):
            for annot in val:
                ts = (parse_iso8601(annot['timestamp']) - EPOCH).total_seconds()
                alist.append((annot, ts))
        self._set_annotations_for_book(book_id, fmt, alist, user_type=user_type, user=user)
Please help? (I'm aware that the annotation browser sorts by last annotated titles but still thought this might be useful)  | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#2 | 
| 
			
			
			
			 want to learn what I want 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,682 
				Karma: 7908443 
				Join Date: Sep 2020 
				
				
				
				Device: none 
				
				
				 | 
	
	
	
		
		
		
		
		 
			
			hmm, I've tried adding a date column in Last Modified PI that should update on any changes to the #ac column (program:  annotation_count()), but this didn't work.
		 
		
	
		
		
		
		
		
		
		
		
		
		
	
	 | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| Advert | |
| 
         | 
    
| 
			
			 | 
		#3 | |
| 
			
			
			
			 want to learn what I want 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,682 
				Karma: 7908443 
				Join Date: Sep 2020 
				
				
				
				Device: none 
				
				
				 | 
	
	
	
		
		
		
		
		 Quote: 
	
 ![]() Would a PTM equivalent of... Code: 
	program: annotation_count() Last edited by Comfy.n; 01-18-2025 at 02:03 AM.  | 
|
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#4 | 
| 
			
			
			
			 creator of calibre 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,609 
				Karma: 28549044 
				Join Date: Oct 2006 
				Location: Mumbai, India 
				
				
				Device: Various 
				
				
				 | 
	
	
	
		
		
		
		
		 
			
			IIRC that template function basically directly queries the database using SQL for a count of annotations for the book id. Anytime the database is updated, the function should return the updated count. Closing the viewer causes it to update the database. But I dont recall the details of how custom columns cache values/when templates are re-evaluated etc.
		 
		
	
		
		
		
		
		
		
		
		
		
		
	
	 | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#5 | 
| 
			
			
			
			 want to learn what I want 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,682 
				Karma: 7908443 
				Join Date: Sep 2020 
				
				
				
				Device: none 
				
				
				 | 
	
	|
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| Advert | |
| 
         | 
    
| 
			
			 | 
		#6 | 
| 
			
			
			
			 Grand Sorcerer 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525 
				Karma: 8065948 
				Join Date: Jan 2010 
				Location: Notts, England 
				
				
				Device: Kobo Libra 2 
				
				
				 | 
	
	
	
		
		
		
		
		 
			
			Composite column values are cached in the db layer. If the underlying data is changed then db.cache.clear_caches() should be called to tell the composite evaluator to re-evaluate the column on next use. Looking at the annotations code in cache, this isn't happening. 
		
	
		
		
		
		
		
		
		
		
		
		
	
	I see 3 choices: 
 A more targeted solution would be not to use a custom column for annotation count, instead calling the function directly. This avoids caching but requires that the processing be done on-demand. @Comfy.h: this might be possible depending on how your action chains work. Instead of referencing the a custom column to get the count, call the function directly.  | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#7 | 
| 
			
			
			
			 want to learn what I want 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,682 
				Karma: 7908443 
				Join Date: Sep 2020 
				
				
				
				Device: none 
				
				
				 | 
	
	
	
		
		
		
		
		 
			
			Will look more into it later, but I'll probably want to keep the annotation count column...  
		
	
		
		
		
		
		
		
		
		
		
		
	
	![]() Another thing I noticed is that on my portable install, which has a setup closer to default settings (few plugins etc.), a Calibre restart is needed to get the annotation count updated. OTOH, on my main install, just reopening a recently highlighted book triggers the annotation count update.  | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
![]()  | 
            
        
    
            
  | 
    
			 
			Similar Threads
		 | 
	||||
| Thread | Thread Starter | Forum | Replies | Last Post | 
| Automatically Setting Date field to file creation date when importing. | Marc_G2 | Library Management | 6 | 07-25-2020 11:35 PM | 
| Date Like a Ninja: 75 Kick-Awesome Date Ideas | Teutonic0 | Self-Promotions by Authors and Publishers | 5 | 02-07-2015 01:26 PM | 
| Edit metadata publish date for a date BC | RickLeFeuvre | Calibre | 2 | 08-29-2014 12:53 AM | 
| Glo Annotation date | John F | Kobo Reader | 4 | 02-21-2013 09:02 AM |