From d3681ca5281f3c881ffef48b5a909d2510175c06 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 10 Aug 2021 12:09:14 +0530 Subject: [PATCH] Also add the library id when dispatching events --- src/calibre/db/cache.py | 6 +++--- src/calibre/db/listeners.py | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index c5af4175ba..0434d923f3 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -427,10 +427,10 @@ class Cache(object): def add_listener(self, event_callback_function): ''' Register a callback function that will be called after certain actions are - taken on this database. The function must take two arguments, the first of - which is the event type (:class:`EventType`) and the second is a tuple - containing event type specific data. + taken on this database. The function must take three arguments: + (:class:`EventType`, library_id, event_type_specific_data) ''' + self.event_dispatcher.library_id = getattr(self, 'server_library_id', self.library_id) self.event_dispatcher.add_listener(event_callback_function) @write_api diff --git a/src/calibre/db/listeners.py b/src/calibre/db/listeners.py index 6e8d39d1c9..b772842f8f 100644 --- a/src/calibre/db/listeners.py +++ b/src/calibre/db/listeners.py @@ -46,6 +46,7 @@ class EventDispatcher: self.refs = [] self.queue = Queue() self.activated = False + self.library_id = '' def add_listener(self, callback): # note that we intentionally leak dead weakrefs. To not do so would @@ -66,7 +67,7 @@ class EventDispatcher: def __call__(self, event_name, *args): if self.activated: - self.queue.put((event_name, args)) + self.queue.put((event_name, self.library_id, args)) def close(self): if self.activated: