Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a "run query" option in the profiler #1826

Open
wants to merge 3 commits into
base: 2.13.x
Choose a base branch
from

Conversation

Louis-Proffit
Copy link

Inside the "view runnable query" panel, a run button enables running the query and checking the results just like "explain query" does

Copy link
Member

@ostrolucky ostrolucky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem to be working for me

image

@@ -90,6 +90,13 @@
connectionName: request.query.get('connection'),
query: request.query.get('query')
})) }}
{% elseif 'run' == page %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that most of the lines are duplicated now. Something like this could be done instead:

{% if page in ['explain', 'page'] %}
  {{ render(controller('Doctrine\\Bundle\\DoctrineBundle\\Controller\\ProfilerController::' ~ page ~ 'Action', {
            token: token,
            panel: 'db',
            connectionName: request.query.get('connection'),
            query: request.query.get('query')
        })) }}

Comment on lines +86 to +95
/**
* Renders the profiler panel for the given token.
*
* @param string $token The profiler token
* @param string $connectionName
* @param int $query
*
* @return Response A Response instance
*/
public function runAction($token, $connectionName, $query)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is old school PHP 5 style code, we don't use it for new stuff

Suggested change
/**
* Renders the profiler panel for the given token.
*
* @param string $token The profiler token
* @param string $connectionName
* @param int $query
*
* @return Response A Response instance
*/
public function runAction($token, $connectionName, $query)
public function runAction(string $token, string $connectionName, int $query): Response

Comment on lines -104 to +111
.sql-runnable button { align-self: end; }
.sql-runnable.sf-toggle-content.sf-toggle-visible { display: flex; flex-direction: row; align-items: center}
.sql-runnable pre { flex-grow: 1}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of this design change. Let's have buttons next to each other, instead on top of each other

</div>
{% endif %}

{% if query.explainable %}
<div id="explain-{{ i }}-{{ loop.parent.loop.index }}" class="sql-explain"></div>
{% endif %}

<div id="run-{{ i }}-{{ loop.parent.loop.index }}" class="sql-explain"></div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be wrapped in {% if query.runnable %} condition? Or you believe the previous condition is not necessary?

Comment on lines +483 to +509
function run(link) {
"use strict";

var targetId = link.getAttribute('data-target-id');
var targetElement = document.getElementById(targetId);

if (targetElement.style.display != 'block') {
if (targetElement.getAttribute('data-sfurl') !== link.href) {
fetch(link.href, {
headers: {'X-Requested-With': 'XMLHttpRequest'}
}).then(async function (response) {
targetElement.innerHTML = await response.text()
targetElement.setAttribute('data-sfurl', link.href)
}, function () {
targetElement.innerHTML = 'An error occurred while loading the query explanation.';
})
}

targetElement.style.display = 'block';
link.innerHTML = 'Hide query result';
} else {
targetElement.style.display = 'none';
link.innerHTML = 'Run query';
}

return false;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please parametrize the function that was copied instead of copying whole thing and just changing few lines

Comment on lines +1 to +23
{% if result is not empty %}
<table>
<thead>
<tr>
{% for key, value in result[0] %}
<th>{{ key }}</th>
{% endfor %}
</tr>

</thead>
<tbody>
{% for row in result %}
<tr>
{% for key, value in row %}
<td>{{ value }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
Result is empty
{% endif %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was also copied (explain.html.twig), please modularize through block/embed it if you believe some stuff have to be different

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants