1
1
import contextlib
2
2
import uuid
3
3
from contextvars import ContextVar
4
+ from dataclasses import dataclass
4
5
from os .path import join , normpath
5
6
6
7
from django .contrib .staticfiles import finders , storage
10
11
from debug_toolbar import panels
11
12
12
13
14
+ @dataclass (eq = True , frozen = True )
13
15
class StaticFile :
14
16
"""
15
17
Representing the different properties of a static file.
16
18
"""
17
19
18
- def __init__ (self , * , path , url ):
19
- self .path = path
20
- self ._url = url
20
+ path : str
21
+ url : str
21
22
22
23
def __str__ (self ):
23
24
return self .path
@@ -72,7 +73,7 @@ def title(self):
72
73
def __init__ (self , * args , ** kwargs ):
73
74
super ().__init__ (* args , ** kwargs )
74
75
self .num_found = 0
75
- self .used_paths = []
76
+ self .used_paths = set ()
76
77
self .request_id = str (uuid .uuid4 ())
77
78
78
79
@classmethod
@@ -88,7 +89,7 @@ def _store_static_files_signal_handler(self, sender, staticfile, **kwargs):
88
89
# concurrent connections and we want to avoid storing of same
89
90
# staticfile from other connections as well.
90
91
if request_id_context_var .get () == self .request_id :
91
- self .used_paths .append (staticfile )
92
+ self .used_paths .add (staticfile )
92
93
93
94
def enable_instrumentation (self ):
94
95
self .ctx_token = request_id_context_var .set (self .request_id )
@@ -112,7 +113,7 @@ def generate_stats(self, request, response):
112
113
{
113
114
"num_found" : self .num_found ,
114
115
"num_used" : len (self .used_paths ),
115
- "staticfiles" : self .used_paths ,
116
+ "staticfiles" : sorted ( self .used_paths ) ,
116
117
"staticfiles_apps" : self .get_staticfiles_apps (),
117
118
"staticfiles_dirs" : self .get_staticfiles_dirs (),
118
119
"staticfiles_finders" : self .get_staticfiles_finders (),
0 commit comments