mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-13 21:56:11 +00:00
Replaced debug output of json.dumps with an indirection to lazy __str__.
json.dumps is a processing intensive operation. This is being called every time data is received from the server (most noticeably during library updates) for debug logging. If the user has debug logging disabled (the default option) then the user is still paying for processing which is discarded. The fix is to add a level of indirection where the dumps function is only called if a string representation of the json is requested; ie. when the debug string is evaluated.
This commit is contained in:
parent
94456ddcd8
commit
7491000a13
5 changed files with 24 additions and 8 deletions
|
@ -15,7 +15,7 @@ import client
|
||||||
from database import reset, get_sync, Database, jellyfin_db, get_credentials
|
from database import reset, get_sync, Database, jellyfin_db, get_credentials
|
||||||
from objects import Objects, Actions
|
from objects import Objects, Actions
|
||||||
from downloader import TheVoid
|
from downloader import TheVoid
|
||||||
from helper import translate, event, settings, window, dialog, api, JSONRPC
|
from helper import translate, event, settings, window, dialog, api, JSONRPC, debug
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ class Events(object):
|
||||||
if server == 'None':
|
if server == 'None':
|
||||||
server = None
|
server = None
|
||||||
|
|
||||||
LOG.info("path: %s params: %s", path, json.dumps(params, indent=4))
|
LOG.info("path: %s params: %s", path, debug.JsonDebugPrinter(params))
|
||||||
|
|
||||||
if '/extrafanart' in base_url:
|
if '/extrafanart' in base_url:
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ import library
|
||||||
import setup
|
import setup
|
||||||
import monitor
|
import monitor
|
||||||
from views import Views, verify_kodi_defaults
|
from views import Views, verify_kodi_defaults
|
||||||
from helper import translate, window, settings, event, dialog
|
from helper import translate, window, settings, event, dialog, debug
|
||||||
from jellyfin import Jellyfin
|
from jellyfin import Jellyfin
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
@ -171,7 +171,7 @@ class Service(xbmc.Monitor):
|
||||||
|
|
||||||
data = json.loads(data)
|
data = json.loads(data)
|
||||||
|
|
||||||
LOG.debug("[ %s: %s ] %s", sender, method, json.dumps(data, indent=4))
|
LOG.debug("[ %s: %s ] %s", sender, method, debug.JsonDebugPrinter(data))
|
||||||
|
|
||||||
if method == 'ServerOnline':
|
if method == 'ServerOnline':
|
||||||
if data.get('ServerId') is None:
|
if data.get('ServerId') is None:
|
||||||
|
|
15
jellyfin_kodi/helper/debug.py
Normal file
15
jellyfin_kodi/helper/debug.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
##################################################################################################
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
##################################################################################################
|
||||||
|
|
||||||
|
class JsonDebugPrinter(object):
|
||||||
|
|
||||||
|
def __init__(self, json):
|
||||||
|
self.json = json
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return json.dumps(self.json, indent=4)
|
|
@ -11,6 +11,7 @@ import requests
|
||||||
from six import string_types
|
from six import string_types
|
||||||
|
|
||||||
from .exceptions import HTTPException
|
from .exceptions import HTTPException
|
||||||
|
from helper import debug
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|
||||||
|
@ -80,7 +81,7 @@ class HTTP(object):
|
||||||
raise AttributeError("Request cannot be empty")
|
raise AttributeError("Request cannot be empty")
|
||||||
|
|
||||||
data = self._request(data)
|
data = self._request(data)
|
||||||
LOG.debug("--->[ http ] %s", json.dumps(data, indent=4))
|
LOG.debug("--->[ http ] %s", debug.JsonDebugPrinter(data))
|
||||||
retry = data.pop('retry', 5)
|
retry = data.pop('retry', 5)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
@ -162,7 +163,7 @@ class HTTP(object):
|
||||||
elapsed = int(r.elapsed.total_seconds() * 1000)
|
elapsed = int(r.elapsed.total_seconds() * 1000)
|
||||||
response = r.json()
|
response = r.json()
|
||||||
LOG.debug("---<[ http ][%s ms]", elapsed)
|
LOG.debug("---<[ http ][%s ms]", elapsed)
|
||||||
LOG.debug(json.dumps(response, indent=4))
|
LOG.debug(debug.JsonDebugPrinter(response))
|
||||||
|
|
||||||
return response
|
return response
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
|
@ -15,7 +15,7 @@ import downloader
|
||||||
import player
|
import player
|
||||||
from client import get_device_id
|
from client import get_device_id
|
||||||
from objects import PlaylistWorker, on_play, on_update, special_listener
|
from objects import PlaylistWorker, on_play, on_update, special_listener
|
||||||
from helper import translate, settings, window, dialog, api, JSONRPC
|
from helper import translate, settings, window, dialog, api, JSONRPC, debug
|
||||||
from jellyfin import Jellyfin
|
from jellyfin import Jellyfin
|
||||||
from webservice import WebService
|
from webservice import WebService
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ class Monitor(xbmc.Monitor):
|
||||||
|
|
||||||
data = json.loads(data)
|
data = json.loads(data)
|
||||||
|
|
||||||
LOG.debug("[ %s: %s ] %s", sender, method, json.dumps(data, indent=4))
|
LOG.debug("[ %s: %s ] %s", sender, method, debug.JsonDebugPrinter(data))
|
||||||
|
|
||||||
if self.sleep:
|
if self.sleep:
|
||||||
LOG.info("System.OnSleep detected, ignore monitor request.")
|
LOG.info("System.OnSleep detected, ignore monitor request.")
|
||||||
|
|
Loading…
Reference in a new issue