Skip to content

Commit c4201fa

Browse files
committed
Rename store_id variants to request_id
This matches the new naming defined in the store module and will make things eaiser to change moving forward. This will break anything using the store internally causing issues for third party packages.
1 parent e7cf575 commit c4201fa

File tree

13 files changed

+81
-74
lines changed

13 files changed

+81
-74
lines changed

debug_toolbar/panels/history/forms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ class HistoryStoreForm(forms.Form):
55
"""
66
Validate params
77
8-
store_id: The key for the store instance to be fetched.
8+
request_id: The key for the store instance to be fetched.
99
"""
1010

11-
store_id = forms.CharField(widget=forms.HiddenInput())
11+
request_id = forms.CharField(widget=forms.HiddenInput())
1212
exclude_history = forms.BooleanField(widget=forms.HiddenInput(), required=False)

debug_toolbar/panels/history/panel.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class HistoryPanel(Panel):
2323
def get_headers(self, request):
2424
headers = super().get_headers(request)
2525
observe_request = self.toolbar.get_observe_request()
26-
store_id = self.toolbar.store_id
27-
if store_id and observe_request(request):
28-
headers["djdt-store-id"] = store_id
26+
request_id = self.toolbar.request_id
27+
if request_id and observe_request(request):
28+
headers["djdt-request-id"] = request_id
2929
return headers
3030

3131
@property
@@ -91,18 +91,18 @@ def content(self):
9191
stores[id] = {
9292
"toolbar": toolbar,
9393
"form": HistoryStoreForm(
94-
initial={"store_id": id, "exclude_history": True}
94+
initial={"request_id": id, "exclude_history": True}
9595
),
9696
}
9797

9898
return render_to_string(
9999
self.template,
100100
{
101-
"current_store_id": self.toolbar.store_id,
101+
"current_request_id": self.toolbar.request_id,
102102
"stores": stores,
103103
"refresh_form": HistoryStoreForm(
104104
initial={
105-
"store_id": self.toolbar.store_id,
105+
"request_id": self.toolbar.request_id,
106106
"exclude_history": True,
107107
}
108108
),

debug_toolbar/panels/history/views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ def history_sidebar(request):
1313
form = HistoryStoreForm(request.GET)
1414

1515
if form.is_valid():
16-
store_id = form.cleaned_data["store_id"]
17-
toolbar = DebugToolbar.fetch(store_id)
16+
request_id = form.cleaned_data["request_id"]
17+
toolbar = DebugToolbar.fetch(request_id)
1818
exclude_history = form.cleaned_data["exclude_history"]
1919
context = {}
2020
if toolbar is None:
21-
# When the store_id has been popped already due to
21+
# When the request_id has been popped already due to
2222
# RESULTS_CACHE_SIZE
2323
return JsonResponse(context)
2424
for panel in toolbar.panels:
@@ -58,7 +58,7 @@ def history_refresh(request):
5858
"toolbar": toolbar,
5959
"form": HistoryStoreForm(
6060
initial={
61-
"store_id": id,
61+
"request_id": id,
6262
"exclude_history": True,
6363
}
6464
),

debug_toolbar/static/debug_toolbar/js/history.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ function refreshHistory() {
2525
const formTarget = djDebug.querySelector(".refreshHistory");
2626
const container = document.getElementById("djdtHistoryRequests");
2727
const oldIds = new Set(
28-
pluckData(container.querySelectorAll("tr[data-store-id]"), "storeId")
28+
pluckData(
29+
container.querySelectorAll("tr[data-request-id]"),
30+
"requestId"
31+
)
2932
);
3033

3134
ajaxForm(formTarget)
3235
.then(function (data) {
3336
// Remove existing rows first then re-populate with new data
3437
container
35-
.querySelectorAll("tr[data-store-id]")
38+
.querySelectorAll("tr[data-request-id]")
3639
.forEach(function (node) {
3740
node.remove();
3841
});
@@ -43,8 +46,8 @@ function refreshHistory() {
4346
.then(function () {
4447
const allIds = new Set(
4548
pluckData(
46-
container.querySelectorAll("tr[data-store-id]"),
47-
"storeId"
49+
container.querySelectorAll("tr[data-request-id]"),
50+
"requestId"
4851
)
4952
);
5053
const newIds = difference(allIds, oldIds);
@@ -58,23 +61,23 @@ function refreshHistory() {
5861
.then(function (refreshInfo) {
5962
refreshInfo.newIds.forEach(function (newId) {
6063
const row = container.querySelector(
61-
`tr[data-store-id="${newId}"]`
64+
`tr[data-request-id="${newId}"]`
6265
);
6366
row.classList.add("flash-new");
6467
});
6568
setTimeout(() => {
6669
container
67-
.querySelectorAll("tr[data-store-id]")
70+
.querySelectorAll("tr[data-request-id]")
6871
.forEach((row) => {
6972
row.classList.remove("flash-new");
7073
});
7174
}, 2000);
7275
});
7376
}
7477

75-
function switchHistory(newStoreId) {
78+
function switchHistory(newRequestId) {
7679
const formTarget = djDebug.querySelector(
77-
".switchHistory[data-store-id='" + newStoreId + "']"
80+
".switchHistory[data-request-id='" + newRequestId + "']"
7881
);
7982
const tbody = formTarget.closest("tbody");
8083

@@ -88,16 +91,16 @@ function switchHistory(newStoreId) {
8891
if (Object.keys(data).length === 0) {
8992
const container = document.getElementById("djdtHistoryRequests");
9093
container.querySelector(
91-
'button[data-store-id="' + newStoreId + '"]'
94+
'button[data-request-id="' + newRequestId + '"]'
9295
).innerHTML = "Switch [EXPIRED]";
9396
}
94-
replaceToolbarState(newStoreId, data);
97+
replaceToolbarState(newRequestId, data);
9598
});
9699
}
97100

98101
$$.on(djDebug, "click", ".switchHistory", function (event) {
99102
event.preventDefault();
100-
switchHistory(this.dataset.storeId);
103+
switchHistory(this.dataset.requestId);
101104
});
102105

103106
$$.on(djDebug, "click", ".refreshHistory", function (event) {

debug_toolbar/static/debug_toolbar/js/toolbar.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ const djdt = {
3737
const inner = current.querySelector(
3838
".djDebugPanelContent .djdt-scroll"
3939
),
40-
storeId = djDebug.dataset.storeId;
41-
if (storeId && inner.children.length === 0) {
40+
requestId = djDebug.dataset.requestId;
41+
if (requestId && inner.children.length === 0) {
4242
const url = new URL(
4343
djDebug.dataset.renderPanelUrl,
4444
window.location
4545
);
46-
url.searchParams.append("store_id", storeId);
46+
url.searchParams.append("request_id", requestId);
4747
url.searchParams.append("panel_id", panelId);
4848
ajax(url).then(function (data) {
4949
inner.previousElementSibling.remove(); // Remove AJAX loader
@@ -270,11 +270,11 @@ const djdt = {
270270
document.getElementById("djDebug").dataset.sidebarUrl;
271271
const slowjax = debounce(ajax, 200);
272272

273-
function handleAjaxResponse(storeId) {
274-
storeId = encodeURIComponent(storeId);
275-
const dest = `${sidebarUrl}?store_id=${storeId}`;
273+
function handleAjaxResponse(requestId) {
274+
requestId = encodeURIComponent(requestId);
275+
const dest = `${sidebarUrl}?request_id=${requestId}`;
276276
slowjax(dest).then(function (data) {
277-
replaceToolbarState(storeId, data);
277+
replaceToolbarState(requestId, data);
278278
});
279279
}
280280

@@ -286,9 +286,11 @@ const djdt = {
286286
// when the header can't be fetched. While it doesn't impede execution
287287
// it's worrisome to developers.
288288
if (
289-
this.getAllResponseHeaders().indexOf("djdt-store-id") >= 0
289+
this.getAllResponseHeaders().indexOf("djdt-request-id") >= 0
290290
) {
291-
handleAjaxResponse(this.getResponseHeader("djdt-store-id"));
291+
handleAjaxResponse(
292+
this.getResponseHeader("djdt-request-id")
293+
);
292294
}
293295
});
294296
origOpen.apply(this, arguments);
@@ -298,8 +300,8 @@ const djdt = {
298300
window.fetch = function () {
299301
const promise = origFetch.apply(this, arguments);
300302
promise.then(function (response) {
301-
if (response.headers.get("djdt-store-id") !== null) {
302-
handleAjaxResponse(response.headers.get("djdt-store-id"));
303+
if (response.headers.get("djdt-request-id") !== null) {
304+
handleAjaxResponse(response.headers.get("djdt-request-id"));
303305
}
304306
// Don't resolve the response via .json(). Instead
305307
// continue to return it to allow the caller to consume as needed.

debug_toolbar/static/debug_toolbar/js/utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ function ajaxForm(element) {
105105
return ajax(url, ajaxData);
106106
}
107107

108-
function replaceToolbarState(newStoreId, data) {
108+
function replaceToolbarState(newRequestId, data) {
109109
const djDebug = document.getElementById("djDebug");
110-
djDebug.setAttribute("data-store-id", newStoreId);
111-
// Check if response is empty, it could be due to an expired storeId.
110+
djDebug.setAttribute("data-request-id", newRequestId);
111+
// Check if response is empty, it could be due to an expired requestId.
112112
Object.keys(data).forEach(function (panelId) {
113113
const panel = document.getElementById(panelId);
114114
if (panel) {

debug_toolbar/templates/debug_toolbar/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{% endblock %}
99
<div id="djDebug" class="djdt-hidden" dir="ltr"
1010
{% if not toolbar.should_render_panels %}
11-
data-store-id="{{ toolbar.store_id }}"
11+
data-request-id="{{ toolbar.request_id }}"
1212
data-render-panel-url="{% url 'djdt:render_panel' %}"
1313
{% endif %}
1414
{% url 'djdt:history_sidebar' as history_url %}

debug_toolbar/templates/debug_toolbar/panels/history_tr.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% load i18n %}
2-
<tr class="{% if id == current_store_id %}djdt-highlighted{% endif %}" id="historyMain_{{ id }}" data-store-id="{{ id }}">
2+
<tr class="{% if id == current_request_id %}djdt-highlighted{% endif %}" id="historyMain_{{ id }}" data-request-id="{{ id }}">
33
<td>
44
{{ store_context.toolbar.stats.HistoryPanel.time|escape }}
55
</td>
@@ -44,7 +44,7 @@
4444
<td class="djdt-actions">
4545
<form method="get" action="{% url 'djdt:history_sidebar' %}">
4646
{{ store_context.form }}
47-
<button data-store-id="{{ id }}" class="switchHistory">Switch</button>
47+
<button data-request-id="{{ id }}" class="switchHistory">Switch</button>
4848
</form>
4949
</td>
5050
</tr>

debug_toolbar/toolbar.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self, request, get_response):
4242
self._panels[panel.panel_id] = panel
4343
self.stats = {}
4444
self.server_timing_stats = {}
45-
self.store_id = None
45+
self.request_id = None
4646
self._created.send(request, toolbar=self)
4747

4848
# Manage panels
@@ -110,16 +110,16 @@ def should_render_panels(self):
110110

111111
def store(self):
112112
# Store already exists.
113-
if self.store_id:
113+
if self.request_id:
114114
return
115-
self.store_id = uuid.uuid4().hex
116-
self._store[self.store_id] = self
115+
self.request_id = uuid.uuid4().hex
116+
self._store[self.request_id] = self
117117
for _ in range(self.config["RESULTS_CACHE_SIZE"], len(self._store)):
118118
self._store.popitem(last=False)
119119

120120
@classmethod
121-
def fetch(cls, store_id):
122-
return cls._store.get(store_id)
121+
def fetch(cls, request_id):
122+
return cls._store.get(request_id)
123123

124124
# Manually implement class-level caching of panel classes and url patterns
125125
# because it's more obvious than going through an abstraction.

debug_toolbar/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
@render_with_toolbar_language
1111
def render_panel(request):
1212
"""Render the contents of a panel"""
13-
toolbar = DebugToolbar.fetch(request.GET["store_id"])
13+
toolbar = DebugToolbar.fetch(request.GET["request_id"])
1414
if toolbar is None:
1515
content = _(
1616
"Data for this panel isn't available anymore. "

0 commit comments

Comments
 (0)