django-debug-toolbar icon indicating copy to clipboard operation
django-debug-toolbar copied to clipboard

Serialize the panels

Open tim-schilling opened this issue 2 years ago • 6 comments

This is a draft PR. I'm keeping my on-going work in this branch. I found that my efforts to close #1807 and #1808 quickly spiraled into a major refactor of core logic.

This currently handles the SQLPanel which required the following changes:

  • Drop raw_params entirely. We'll need to serialize the parameters every time now so we can't rely on the original params
  • Refactor the SQL queries to use a djdt_query_id which uniquely identifies each query. The SQL forms now reference this id and avoid passing SQL to be executed.
  • Move the formatting logic of SQL queries back to just before rendering. Otherwise we're rendering and storing the html in the store (I could be convinced I'm over-engineering for the future)

In addition this also changed our design for Panel

  • load_stats_from_store - Generates a Panel instance with the passed in data.
  • Panel.panel_id is now a class member to avoid needing to instantiate a panel to programatically get the panel id. With the new focus on fetching data for a specific panel given its ID, this became more of a need

tim-schilling avatar Aug 21 '23 02:08 tim-schilling

I think this is at a point where we can add some async tests to confirm that this approach will work or not.

tim-schilling avatar Aug 21 '23 02:08 tim-schilling

is this (somewhat) backwards compatible for third party panels?

While it doesn't break any documented APIs for the panel to function itself, this version is not backwards compatible since it loads the content for the panel from the store (render_panel view). That will need to be made backwards compatible to make this generally backwards compatible.

tim-schilling avatar Aug 21 '23 12:08 tim-schilling

@matthiask I'm back to forcing everything that can't be serialized to JSON to a str. Otherwise we're trying to do it manually per panel which will involve a function that's likely going to do similar object and collection iteration as json.dumps().

tim-schilling avatar Aug 29 '23 00:08 tim-schilling

This assumes we'll have some shared memory store for the cache hence the change to should_render_panels

tim-schilling avatar Sep 05 '23 01:09 tim-schilling

from the above changes in consideration in consideration I was able able to run example with async calls image

image

however I believe this async example would also work without serialised panels.

salty-ivy avatar Mar 05 '24 13:03 salty-ivy

however I believe this async example would also work without serialised panels.

Why is that?

tim-schilling avatar Mar 10 '24 18:03 tim-schilling