Mobileread
database2.py deletion notifications
#1  kiwidude 02-18-2011, 05:23 PM
Is the notify=True argument on the majority of functions in database2.py historical code, for future usage, or just selectively used?

I wanted to get notifications about rows being deleted in my plugin so that I could update some id mapping caches I maintain. However I see that while all the infrastructure is there, the call to delete_book sets notify=False. Further searches revealed only one call to add_event_listener in the codebase, and that was in tag_viewer.py which responded to any notification it might receive.

In the end I chose an approach of db.data.has_id() when I retrieve an id from my cache to verify it is still valid and remove it if not. Anything else I could/should have done instead?
Reply 

#2  kovidgoyal 02-18-2011, 05:27 PM
IIRC it's used in a couple of places. It was originally going to be much more comprehensively used, but there turned out to be not much need for it.

Historically the in memory cache was not nearly as comprehensive as it is now, and so querying for existence was much more costly than it is now.
Reply 

#3  kiwidude 02-18-2011, 05:39 PM
Thanks Kovid.
Reply 

#4  chaley 02-18-2011, 05:45 PM
Quote kiwidude
In the end I chose an approach of db.data.has_id() when I retrieve an id from my cache to verify it is still valid and remove it if not. Anything else I could/should have done instead?
has_id is extremely fast, simply testing the existence of x[id] in a list. If using has_id solves your problem, then go for it.

We might consider a publish and subscribe interface on db.data, calling the supplied subscription method whenever the cache changes. An interface at the cache level would be lower-level than the current notifier and possibly more accurate, signaling deletions, additions, and replacements. However, I don't think we should do this until (if and when) we have more cases where it would be used, because changing the interface after it is used would be a genuine bother.
Reply 

Today's Posts | Search this Thread | Login | Register