-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54ff730
commit 3fb2745
Showing
20 changed files
with
208 additions
and
44 deletions.
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
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
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.