comparison src/server/server.py @ 985:64826e69f365

pages: cache mechanism, first draft: a cache mechanism has been implemented to retrieve pages with a complexe rendering and/or calling expensive methods (e.g. network calls). For now it's is done only for Pubsub and with service profile (i.e. profile used when user is not logged in). When a LiberviaPage use cache, node is subscribed, and as long as no event is received (even can be item update, item retraction, or node deletion), the cached page is returned. This is a first draft, it is planed to handle in the future logged users (which can be tricky as we must not let (un)subscribed node if user is not willing to), multi-nodes pages (e.g.: item + comments) and cache for page not depending on pubsub (e.g. chat).
author Goffi <goffi@goffi.org>
date Sun, 19 Nov 2017 17:18:14 +0100
parents f0fc28b3bd1e
children 6daa59d44ee2
comparison
equal deleted inserted replaced
984:f0fc28b3bd1e 985:64826e69f365
51 import urllib 51 import urllib
52 from httplib import HTTPS_PORT 52 from httplib import HTTPS_PORT
53 import libervia 53 import libervia
54 from libervia.server.pages import LiberviaPage 54 from libervia.server.pages import LiberviaPage
55 from libervia.server.utils import quote 55 from libervia.server.utils import quote
56 from functools import partial
56 57
57 try: 58 try:
58 import OpenSSL 59 import OpenSSL
59 from twisted.internet import ssl 60 from twisted.internet import ssl
60 except ImportError: 61 except ImportError:
1391 self._cleanup = [] 1392 self._cleanup = []
1392 1393
1393 self.signal_handler = SignalHandler(self) 1394 self.signal_handler = SignalHandler(self)
1394 self.sessions = {} # key = session value = user 1395 self.sessions = {} # key = session value = user
1395 self.prof_connected = set() # Profiles connected 1396 self.prof_connected = set() # Profiles connected
1397 self.ns_map = {} # map of short name to namespaces
1396 1398
1397 ## bridge ## 1399 ## bridge ##
1398 try: 1400 try:
1399 self.bridge = Bridge() 1401 self.bridge = Bridge()
1400 except BridgeExceptionNoService: 1402 except BridgeExceptionNoService:
1401 print(u"Can't connect to SàT backend, are you sure it's launched ?") 1403 print(u"Can't connect to SàT backend, are you sure it's launched ?")
1402 sys.exit(1) 1404 sys.exit(1)
1403 self.bridge.bridgeConnect(callback=self._bridgeCb, errback=self._bridgeEb) 1405 self.bridge.bridgeConnect(callback=self._bridgeCb, errback=self._bridgeEb)
1404 1406
1407 def _namespacesGetCb(self, ns_map):
1408 self.ns_map = ns_map
1409
1410 def _namespacesGetEb(self, failure_):
1411 log.error(_(u"Can't get namespaces map: {msg}").format(msg=failure_))
1412
1405 def backendReady(self, dummy): 1413 def backendReady(self, dummy):
1406 self.root = root = LiberviaRootResource(self.options, self.html_dir) 1414 self.root = root = LiberviaRootResource(self.options, self.html_dir)
1407 _register = Register(self) 1415 _register = Register(self)
1408 _upload_radiocol = UploadManagerRadioCol(self) 1416 _upload_radiocol = UploadManagerRadioCol(self)
1409 _upload_avatar = UploadManagerAvatar(self) 1417 _upload_avatar = UploadManagerAvatar(self)
1418 d = self.bridgeCall('namespacesGet')
1419 d.addCallback(self._namespacesGetCb)
1420 d.addErrback(self._namespacesGetEb)
1410 self.signal_handler.plugRegister(_register) 1421 self.signal_handler.plugRegister(_register)
1411 self.bridge.register_signal("connected", self.signal_handler.connected) 1422 self.bridge.register_signal("connected", self.signal_handler.connected)
1412 self.bridge.register_signal("disconnected", self.signal_handler.disconnected) 1423 self.bridge.register_signal("disconnected", self.signal_handler.disconnected)
1413 #core 1424 #core
1414 for signal_name in ['presenceUpdate', 'messageNew', 'subscribe', 'contactDeleted', 1425 for signal_name in ['presenceUpdate', 'messageNew', 'subscribe', 'contactDeleted',
1440 # static pages 1451 # static pages
1441 self.putChild('blog', MicroBlog(self)) 1452 self.putChild('blog', MicroBlog(self))
1442 self.putChild(C.THEMES_URL, ProtectedFile(self.themes_dir)) 1453 self.putChild(C.THEMES_URL, ProtectedFile(self.themes_dir))
1443 1454
1444 LiberviaPage.importPages(self) 1455 LiberviaPage.importPages(self)
1456 self.bridge.register_signal("psEventRaw", partial(LiberviaPage.onNodeEvent, self), "plugin")
1445 1457
1446 # media dirs 1458 # media dirs
1447 # FIXME: get rid of dirname and "/" in C.XXX_DIR 1459 # FIXME: get rid of dirname and "/" in C.XXX_DIR
1448 self.putChild(os.path.dirname(C.MEDIA_DIR), ProtectedFile(self.media_dir)) 1460 self.putChild(os.path.dirname(C.MEDIA_DIR), ProtectedFile(self.media_dir))
1449 self.cache_resource = web_resource.NoResource() 1461 self.cache_resource = web_resource.NoResource()