-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support serializable toolbar #1432
Closed
tim-schilling
wants to merge
4
commits into
django-commons:main
from
tim-schilling:serializable-toolbar
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3cb0970
Create basic memory store for toolbar to reproduce existing functiona…
tim-schilling 9cf5bfd
Support storing serialized panel stats directly into the store.
tim-schilling 54ff730
Support stats only version of toolbar.
tim-schilling 3fb2745
WIP
tim-schilling File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from debug_toolbar import store | ||
from debug_toolbar.models import PanelStore, ToolbarStore | ||
|
||
|
||
class DBStore(store.BaseStore): | ||
@classmethod | ||
def ids(cls): | ||
return ( | ||
ToolbarStore.objects.using("debug_toolbar") | ||
.values_list("key", flat=True) | ||
.order_by("created") | ||
) | ||
|
||
@classmethod | ||
def exists(cls, store_id): | ||
return ToolbarStore.objects.using("debug_toolbar").filter(key=store_id).exists() | ||
|
||
@classmethod | ||
def set(cls, store_id): | ||
_, created = ToolbarStore.objects.using("debug_toolbar").get_or_create( | ||
key=store_id | ||
) | ||
if ( | ||
created | ||
and ToolbarStore.objects.using("debug_toolbar").all().count() | ||
> cls.config["RESULTS_CACHE_SIZE"] | ||
): | ||
ToolbarStore.objects.using("debug_toolbar").earliest("created").delete() | ||
|
||
@classmethod | ||
def delete(cls, store_id): | ||
ToolbarStore.objects.using("debug_toolbar").filter(key=store_id).delete() | ||
|
||
@classmethod | ||
def save_panel(cls, store_id, panel_id, stats=None): | ||
toolbar, _ = ToolbarStore.objects.using("debug_toolbar").get_or_create( | ||
key=store_id | ||
) | ||
toolbar.panelstore_set.update_or_create( | ||
panel=panel_id, defaults={"data": store.serialize(stats)} | ||
) | ||
|
||
@classmethod | ||
def panel(cls, store_id, panel_id): | ||
panel = ( | ||
PanelStore.objects.using("debug_toolbar") | ||
.filter(toolbar__key=store_id, panel=panel_id) | ||
.first() | ||
) | ||
return {} if not panel else store.deserialize(panel.data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Generated by Django 3.1.5 on 2021-01-09 17:02 | ||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
initial = True | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="ToolbarStore", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("created", models.DateTimeField(auto_now_add=True)), | ||
("key", models.CharField(max_length=64, unique=True)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="PanelStore", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("created", models.DateTimeField(auto_now_add=True)), | ||
("panel", models.CharField(max_length=128)), | ||
("data", models.TextField()), | ||
( | ||
"toolbar", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="debug_toolbar.toolbarstore", | ||
), | ||
), | ||
], | ||
), | ||
migrations.AddConstraint( | ||
model_name="panelstore", | ||
constraint=models.UniqueConstraint( | ||
fields=("toolbar", "panel"), name="unique_toolbar_panel" | ||
), | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.db import models | ||
|
||
|
||
class ToolbarStore(models.Model): | ||
created = models.DateTimeField(auto_now_add=True) | ||
key = models.CharField(max_length=64, unique=True) | ||
|
||
|
||
class PanelStore(models.Model): | ||
created = models.DateTimeField(auto_now_add=True) | ||
toolbar = models.ForeignKey(ToolbarStore, on_delete=models.CASCADE) | ||
panel = models.CharField(max_length=128) | ||
data = models.TextField() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these two methods complete?
deserialize_stats
serialize_stats