Commit bda27583 authored by Frank Bessou's avatar Frank Bessou 🍁
Browse files

Transform RqlIOSchemaHolder into a singleton

Its two class methods get_schema and get_schema_hash will only compute
the schema once. They where computed every time the schema was

Closes #1.
parent 2ec46e035500
......@@ -28,6 +28,8 @@ class RqlIOSchemaHolder(object):
so it can decide to update the locally stored schema if
the integrity is not valid.
_schema = None
_hash = None
def format_schema(typeNames,
......@@ -70,10 +72,13 @@ class RqlIOSchemaHolder(object):
} for row in relationsFrom]
def get_schema(self):
def get_schema(cls, cnx):
if cls._schema is not None:
return cls._schema
entities = []
etypes = self._cw.execute('Any T WHERE T is CWEType')
etypes = cnx.execute('Any T WHERE T is CWEType')
for etype in etypes:
eid = etype[0]
rql_requests = [
......@@ -122,12 +127,16 @@ class RqlIOSchemaHolder(object):
ATTR ordernum ON"""
rsets = [self._cw.execute(request) for request in rql_requests]
rsets = [cnx.execute(request) for request in rql_requests]
return {"entities": entities}
cls._schema = {"entities": entities}
return cls._schema
def get_schema_hash(self):
return hashlib.md5(
def get_schema_hash(cls, cnx):
if cls._hash is not None:
return cls._hash
cls._hash = hashlib.md5(
return cls._hash
......@@ -75,15 +75,15 @@ class match_request_content_type(ExpectedValuePredicate):
return header
class RqlIOSchemaController(Controller, RqlIOSchemaHolder):
class RqlIOSchemaController(Controller):
__regid__ = 'rqlio_schema'
__select__ = match_http_method('GET', 'HEAD')
def publish(self, rset=None):
self._cw.add_header('Etag', self.get_schema_hash)
self._cw.add_header('Etag', RqlIOSchemaHolder.get_schema_hash(self._cw))
return json.dumps(
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment