jazzband / django-silk

Silky smooth profiling for Django
MIT License
4.42k stars 333 forks source link

Enhance tables_involved Property to Include Tables from Update and Delete Operations #717

Closed emregeldegul closed 1 month ago

emregeldegul commented 3 months ago

This pull request addresses the issue where the tables_involved property of the SQLQuery model fails to recognize tables involved in UPDATE operation. The current implementation only captures tables involved in SELECT and JOIN operations.

The updated implementation includes UPDATE operation to ensure comprehensive table identification. The modified code is as follows:

class SQLQuery(models.Model):
    query = TextField()
    ...

    @property
    def tables_involved(self):
        ...
        for idx, component in enumerate(components):
            ...
            if (
                component.lower() == "from"
                or component.lower() == "join"
                or component.lower() == "as"
                or component.lower() == "update"
            ):
                ...
        return tables

By including update statement, this change ensures that all relevant tables are captured for a more complete SQL query analysis. This update helps in better tracking and debugging of SQL queries within Django applications.

Fixes #716