diff libervia/web/pages/_browser/cache.py @ 1544:9b451115e726

browser (cache): replace `print` by `log` calls
author Goffi <goffi@goffi.org>
date Thu, 06 Jul 2023 12:07:29 +0200
parents d7c78722e4f8
children
line wrap: on
line diff
--- a/libervia/web/pages/_browser/cache.py	Thu Jul 06 12:05:48 2023 +0200
+++ b/libervia/web/pages/_browser/cache.py	Thu Jul 06 12:07:29 2023 +0200
@@ -25,12 +25,12 @@
         else:
             cache = json.loads(cache)
             if cache['metadata']['session_uuid'] != session_uuid:
-                print("data in cache are not valid for this session, resetting")
+                log.debug("data in cache are not valid for this session, resetting")
                 del storage['libervia_cache']
                 self.request_data_from_backend()
             else:
                 self._cache = cache
-                print("storage cache is used")
+                log.debug("storage cache is used")
 
     @property
     def roster(self):
@@ -41,9 +41,9 @@
         return self._cache['identities']
 
     def update(self):
-        print(f"updating: {self._cache}")
+        log.debug(f"updating: {self._cache}")
         storage['libervia_cache'] = json.dumps(self._cache)
-        print("cache stored")
+        log.debug("cache stored")
 
     def _store_if_complete(self):
         self._completed_count -= 1
@@ -52,7 +52,7 @@
             self.update()
 
     def get_contacts_cb(self, contacts):
-        print("roster received")
+        log.debug("roster received")
         roster = self._cache['roster']
         for contact_jid, attributes, groups in contacts:
             roster[contact_jid] = {
@@ -62,7 +62,7 @@
         self._store_if_complete()
 
     def identities_base_get_cb(self, identities_raw):
-        print("base identities received")
+        log.debug("base identities received")
         identities = json.loads(identities_raw)
         self._cache['identities'].update(identities)
         self._store_if_complete()
@@ -80,12 +80,12 @@
             'identities': {},
         }
         self._completed_count = 2
-        print("requesting roster to backend")
+        log.debug("requesting roster to backend")
         bridge.contacts_get(
             callback=self.get_contacts_cb,
             errback=lambda e: self.request_failed(e, "Can't get contacts: {exc}")
         )
-        print("requesting base identities to backend")
+        log.debug("requesting base identities to backend")
         bridge.identities_base_get(
             callback=self.identities_base_get_cb,
             errback=lambda e: self.request_failed(e, "Can't get base identities: {exc}")
@@ -95,6 +95,7 @@
         """Check that identities for entities exist, request them otherwise"""
         to_get = {e for e in entities if e not in self._cache['identities']}
         if to_get:
+            log.debug(f"we don't have all identities in cache, getting {to_get}")
             try:
                 new_identities_raw = await async_bridge.identities_get(
                     list(to_get),
@@ -107,7 +108,7 @@
                 )
             else:
                 new_identities = json.loads(new_identities_raw)
-                print(f"new identities: {new_identities.keys()}")
+                log.debug(f"new identities: {new_identities.keys()}")
                 self._cache['identities'].update(new_identities)
                 self.update()
         else:
@@ -130,7 +131,7 @@
             try:
                 identity = self.identities[entity_jid]
             except KeyError:
-                print(f"missing identity: {entity_jid}")
+                log.debug(f"missing identity: {entity_jid}")
                 return False
         return any(text in n.lower() for n in identity['nicknames'])