Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 01-17-2025, 11:47 PM   #1
Comfy.n
want to learn what I want
Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.
 
Posts: 1,610
Karma: 7891011
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)
... because of that annot['timestamp'] reference.

Please help?

(I'm aware that the annotation browser sorts by last annotated titles but still thought this might be useful)
Comfy.n is offline   Reply With Quote
Old 01-18-2025, 12:09 AM   #2
Comfy.n
want to learn what I want
Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.
 
Posts: 1,610
Karma: 7891011
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.
Comfy.n is offline   Reply With Quote
Advert
Old 01-18-2025, 12:19 AM   #3
Comfy.n
want to learn what I want
Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.
 
Posts: 1,610
Karma: 7891011
Join Date: Sep 2020
Device: none
Quote:
Originally Posted by Comfy.n View Post
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.
And that's because, I just noticed, the #ac count will only update on Calibre restart.

Would a PTM equivalent of...

Code:
program:  annotation_count()
refresh upon closing a just annotated book?

Last edited by Comfy.n; 01-18-2025 at 01:03 AM.
Comfy.n is offline   Reply With Quote
Old 01-18-2025, 12:29 AM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,322
Karma: 27111242
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.
kovidgoyal is online now   Reply With Quote
Old 01-18-2025, 12:53 AM   #5
Comfy.n
want to learn what I want
Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.
 
Posts: 1,610
Karma: 7891011
Join Date: Sep 2020
Device: none
Quote:
Originally Posted by kovidgoyal View Post
Closing the viewer causes it to update the database.
In my case, I just noticed closing the viewer isn't enough. Reopening a just highlighted book (using a downloaded news standard epub for testing), does update the count instantaneously.
Comfy.n is offline   Reply With Quote
Advert
Old 01-18-2025, 04:53 AM   #6
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,425
Karma: 8012664
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:
  • Do nothing. The caches will be cleared from time to time because of other operations.
  • cache.clear_caches() whenever the annotations change. This is a rather large hammer.
  • When annotations change, loop through the fields (columns) and clear the render cache for composites. This is a smaller hammer but requires more work to set up the loop.

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.
chaley is offline   Reply With Quote
Old 01-18-2025, 05:10 AM   #7
Comfy.n
want to learn what I want
Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.Comfy.n ought to be getting tired of karma fortunes by now.
 
Posts: 1,610
Karma: 7891011
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.
Comfy.n is offline   Reply With Quote
Reply


Forum Jump

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 10:35 PM
Date Like a Ninja: 75 Kick-Awesome Date Ideas Teutonic0 Self-Promotions by Authors and Publishers 5 02-07-2015 12:26 PM
Edit metadata publish date for a date BC RickLeFeuvre Calibre 2 08-28-2014 11:53 PM
Glo Annotation date John F Kobo Reader 4 02-21-2013 08:02 AM


All times are GMT -4. The time now is 11:32 AM.


MobileRead.com is a privately owned, operated and funded community.