@@ -10,36 +10,12 @@ class BenchmarkController < RageController::API
1010 if File . exist? ( dataset_path )
1111 @dataset_items = JSON . parse ( File . read ( dataset_path ) )
1212 end
13+ def self . dataset_items = @dataset_items
1314
14- # Load static files into memory
15- MIME_TYPES = {
16- '.css' => 'text/css' ,
17- '.js' => 'application/javascript' ,
18- '.html' => 'text/html' ,
19- '.woff2' => 'font/woff2' ,
20- '.svg' => 'image/svg+xml' ,
21- '.webp' => 'image/webp' ,
22- '.json' => 'application/json'
23- } . freeze
24-
25- static_dir = File . join DATA_DIR , 'static'
26- @static_files_cache = { }
27- if Dir . exist? ( static_dir )
28- Dir . foreach ( static_dir ) do |name |
29- next if name == '.' || name == '..'
30- path = File . join ( static_dir , name )
31- next unless File . file? ( path )
32- ext = File . extname ( name )
33- ct = MIME_TYPES . fetch ( ext , 'application/octet-stream' )
34- @static_files_cache [ name ] = { data : File . binread ( path ) , content_type : ct }
35- end
36- end
15+ FileUtils . cp_r ( File . join ( DATA_DIR , 'static' ) , File . join ( Rage . root , 'public' , 'static' ) )
3716
3817 PG_QUERY = 'SELECT id, name, category, price, quantity, active, tags, rating_score, rating_count FROM items WHERE price BETWEEN $1 AND $2 LIMIT $3'
3918
40- def self . dataset_items = @dataset_items
41- def self . static_files_cache = @static_files_cache
42-
4319 before_action do
4420 headers [ "server" ] = "rage"
4521 end
@@ -126,15 +102,6 @@ def async_db
126102 render json : { items : items , count : items . length }
127103 end
128104
129- def static_file
130- if entry = self . class . static_files_cache [ params [ :filename ] ]
131- headers [ 'content-type' ] = entry [ :content_type ]
132- render plain : entry [ :data ]
133- else
134- head 404
135- end
136- end
137-
138105 def upload
139106 rack_input = request . send ( :rack_request ) . env [ "rack.input" ]
140107 rack_input . rewind
0 commit comments