108 def process_response(self, response): |
108 def process_response(self, response): |
109 unsubscribe_to_debug_channel("rql", self.collect_rql_queries) |
109 unsubscribe_to_debug_channel("rql", self.collect_rql_queries) |
110 unsubscribe_to_debug_channel("sql", self.collect_sql_queries) |
110 unsubscribe_to_debug_channel("sql", self.collect_sql_queries) |
111 |
111 |
112 |
112 |
|
113 class SQLDebugPanel(DebugPanel): |
|
114 """ |
|
115 CubicWeb SQL debug panel |
|
116 """ |
|
117 |
|
118 """ |
|
119 Excepted formats: |
|
120 SQL: { |
|
121 'rql_query_tracing_token': 'some_token', |
|
122 'args': {dict with some args}, |
|
123 'rollback': False|True, |
|
124 'time': time_in_float, |
|
125 'sql':_sql_query_as_a_string, |
|
126 } |
|
127 """ |
|
128 |
|
129 name = 'SQL' |
|
130 title = 'SQL queries' |
|
131 nav_title = 'SQL' |
|
132 nav_subtitle_style = 'progress-bar-info' |
|
133 |
|
134 has_content = True |
|
135 template = 'cubicweb.pyramid:debug_toolbar_templates/sql.dbtmako' |
|
136 |
|
137 def __init__(self, request): |
|
138 self.data = { |
|
139 'rql_queries': [], |
|
140 'sql_queries': [], |
|
141 'highlight': highlight_html, |
|
142 'generate_css': generate_css, |
|
143 } |
|
144 subscribe_to_debug_channel("rql", self.collect_rql_queries) |
|
145 subscribe_to_debug_channel("sql", self.collect_sql_queries) |
|
146 |
|
147 @property |
|
148 def nav_subtitle(self): |
|
149 return len(self.data['sql_queries']) |
|
150 |
|
151 def collect_rql_queries(self, rql_query): |
|
152 self.data["rql_queries"].append(rql_query) |
|
153 |
|
154 # link sql queries to rql's one |
|
155 for sql_query in self.data["sql_queries"]: |
|
156 if sql_query["rql_query_tracing_token"] == rql_query["rql_query_tracing_token"]: |
|
157 sql_query["from_rql_query"] = rql_query |
|
158 |
|
159 def collect_sql_queries(self, sql_query): |
|
160 sql_query["from_rql_query"] = None |
|
161 self.data["sql_queries"].append(sql_query) |
|
162 |
|
163 def process_response(self, response): |
|
164 unsubscribe_to_debug_channel("rql", self.collect_rql_queries) |
|
165 unsubscribe_to_debug_channel("sql", self.collect_sql_queries) |
|
166 |
|
167 |
113 def includeme(config): |
168 def includeme(config): |
114 config.add_debugtoolbar_panel(CubicWebDebugPanel) |
169 config.add_debugtoolbar_panel(CubicWebDebugPanel) |
115 config.add_debugtoolbar_panel(RQLDebugPanel) |
170 config.add_debugtoolbar_panel(RQLDebugPanel) |
|
171 config.add_debugtoolbar_panel(SQLDebugPanel) |