litestack 0.3.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.standard.yml +3 -0
- data/BENCHMARKS.md +34 -7
- data/CHANGELOG.md +21 -0
- data/Gemfile +1 -5
- data/Gemfile.lock +92 -0
- data/README.md +120 -6
- data/ROADMAP.md +45 -0
- data/Rakefile +3 -1
- data/WHYLITESTACK.md +1 -1
- data/assets/litecache_metrics.png +0 -0
- data/assets/litedb_metrics.png +0 -0
- data/assets/litemetric_logo_teal.png +0 -0
- data/assets/litesearch_logo_teal.png +0 -0
- data/bench/bench.rb +17 -10
- data/bench/bench_cache_rails.rb +10 -13
- data/bench/bench_cache_raw.rb +17 -22
- data/bench/bench_jobs_rails.rb +19 -13
- data/bench/bench_jobs_raw.rb +17 -10
- data/bench/bench_queue.rb +4 -6
- data/bench/rails_job.rb +5 -7
- data/bench/skjob.rb +4 -4
- data/bench/uljob.rb +6 -6
- data/lib/action_cable/subscription_adapter/litecable.rb +5 -8
- data/lib/active_job/queue_adapters/litejob_adapter.rb +6 -8
- data/lib/active_record/connection_adapters/litedb_adapter.rb +65 -75
- data/lib/active_support/cache/litecache.rb +38 -41
- data/lib/generators/litestack/install/install_generator.rb +3 -3
- data/lib/generators/litestack/install/templates/database.yml +7 -1
- data/lib/litestack/liteboard/liteboard.rb +269 -149
- data/lib/litestack/litecable.rb +44 -40
- data/lib/litestack/litecable.sql.yml +22 -11
- data/lib/litestack/litecache.rb +80 -89
- data/lib/litestack/litecache.sql.yml +81 -22
- data/lib/litestack/litecache.yml +1 -1
- data/lib/litestack/litedb.rb +39 -38
- data/lib/litestack/litejob.rb +31 -31
- data/lib/litestack/litejobqueue.rb +107 -106
- data/lib/litestack/litemetric.rb +83 -95
- data/lib/litestack/litemetric.sql.yml +244 -234
- data/lib/litestack/litemetric_collector.sql.yml +38 -41
- data/lib/litestack/litequeue.rb +39 -41
- data/lib/litestack/litequeue.sql.yml +39 -31
- data/lib/litestack/litescheduler.rb +84 -0
- data/lib/litestack/litesearch/index.rb +260 -0
- data/lib/litestack/litesearch/model.rb +179 -0
- data/lib/litestack/litesearch/schema.rb +190 -0
- data/lib/litestack/litesearch/schema_adapters/backed_adapter.rb +143 -0
- data/lib/litestack/litesearch/schema_adapters/basic_adapter.rb +137 -0
- data/lib/litestack/litesearch/schema_adapters/contentless_adapter.rb +14 -0
- data/lib/litestack/litesearch/schema_adapters/standalone_adapter.rb +31 -0
- data/lib/litestack/litesearch/schema_adapters.rb +4 -0
- data/lib/litestack/litesearch.rb +34 -0
- data/lib/litestack/litesupport.rb +85 -186
- data/lib/litestack/railtie.rb +1 -1
- data/lib/litestack/version.rb +2 -2
- data/lib/litestack.rb +7 -4
- data/lib/railties/rails/commands/dbconsole.rb +11 -15
- data/lib/sequel/adapters/litedb.rb +18 -22
- data/lib/sequel/adapters/shared/litedb.rb +168 -168
- data/scripts/build_metrics.rb +91 -0
- data/scripts/test_cable.rb +30 -0
- data/scripts/test_job_retry.rb +33 -0
- data/scripts/test_metrics.rb +60 -0
- data/template.rb +2 -2
- metadata +112 -7
@@ -1,18 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'hanami/router'
|
3
|
-
require 'tilt'
|
4
|
-
require 'erubi'
|
5
2
|
|
6
|
-
|
7
|
-
|
3
|
+
require "hanami/router"
|
4
|
+
require "tilt"
|
5
|
+
require "erubi"
|
8
6
|
|
9
|
-
|
7
|
+
# require relative so we pick the gem version that corresponds to the liteboard binary
|
8
|
+
require_relative "../../litestack/litemetric"
|
10
9
|
|
11
|
-
|
12
|
-
@@
|
10
|
+
class Liteboard
|
11
|
+
@@resolutions = {"minute" => [300, 12], "hour" => [3600, 24], "day" => [3600 * 24, 7], "week" => [3600 * 24 * 7, 53], "year" => [3600 * 24 * 365, 100]}
|
12
|
+
@@res_mapping = {"hour" => "minute", "day" => "hour", "week" => "day", "year" => "week"}
|
13
13
|
@@templates = {}
|
14
14
|
@@app = Hanami::Router.new do
|
15
|
-
|
16
15
|
get "/", to: ->(env) do
|
17
16
|
Liteboard.new(env).call(:index)
|
18
17
|
end
|
@@ -24,7 +23,7 @@ class Liteboard
|
|
24
23
|
get "/topics/Litecache", to: ->(env) do
|
25
24
|
Liteboard.new(env).call(:litecache)
|
26
25
|
end
|
27
|
-
|
26
|
+
|
28
27
|
get "/topics/Litedb", to: ->(env) do
|
29
28
|
Liteboard.new(env).call(:litedb)
|
30
29
|
end
|
@@ -32,9 +31,7 @@ class Liteboard
|
|
32
31
|
get "/topics/Litecable", to: ->(env) do
|
33
32
|
Liteboard.new(env).call(:litecable)
|
34
33
|
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
34
|
+
end
|
38
35
|
|
39
36
|
def initialize(env)
|
40
37
|
@env = env
|
@@ -43,8 +40,8 @@ class Liteboard
|
|
43
40
|
@lm = Litemetric.instance
|
44
41
|
end
|
45
42
|
|
46
|
-
def params(key)
|
47
|
-
URI.decode_uri_component(
|
43
|
+
def params(key)
|
44
|
+
URI.decode_uri_component(@params[key].to_s)
|
48
45
|
end
|
49
46
|
|
50
47
|
def call(method)
|
@@ -52,24 +49,24 @@ class Liteboard
|
|
52
49
|
res = send(method)
|
53
50
|
after(res)
|
54
51
|
end
|
55
|
-
|
56
|
-
def after(body=nil)
|
57
|
-
[200, {
|
52
|
+
|
53
|
+
def after(body = nil)
|
54
|
+
[200, {"Cache-Control" => "no-cache"}, [body]]
|
58
55
|
end
|
59
56
|
|
60
57
|
def before
|
61
|
-
@res = params(:res) ||
|
58
|
+
@res = params(:res) || "day"
|
62
59
|
@resolution = @@res_mapping[@res]
|
63
|
-
if
|
64
|
-
@res =
|
65
|
-
@resolution = @@res_mapping[@res]
|
60
|
+
if !@resolution
|
61
|
+
@res = "day"
|
62
|
+
@resolution = @@res_mapping[@res]
|
66
63
|
end
|
67
64
|
@step = @@resolutions[@resolution][0]
|
68
65
|
@count = @@resolutions[@resolution][1]
|
69
|
-
@order = params(:order)
|
70
|
-
@order = nil if @order ==
|
71
|
-
@dir = params(:dir)
|
72
|
-
@dir =
|
66
|
+
@order = params(:order)
|
67
|
+
@order = nil if @order == ""
|
68
|
+
@dir = params(:dir)
|
69
|
+
@dir = "desc" if @dir.nil? || @dir == ""
|
73
70
|
@dir = @dir.downcase
|
74
71
|
@idir = if @dir == "asc"
|
75
72
|
"desc"
|
@@ -77,149 +74,277 @@ class Liteboard
|
|
77
74
|
"asc"
|
78
75
|
end
|
79
76
|
@search = params(:search)
|
80
|
-
@search = nil if @search ==
|
77
|
+
@search = nil if @search == ""
|
81
78
|
@topics = @lm.topic_summaries(@resolution, @step * @count, @order, @dir, @search)
|
82
79
|
end
|
83
|
-
|
80
|
+
|
84
81
|
def index
|
85
|
-
@order
|
82
|
+
@order ||= "topic"
|
86
83
|
@topics.each do |topic|
|
87
|
-
|
88
|
-
|
89
|
-
end
|
84
|
+
data_points = @lm.topic_data_points(@step, @count, @resolution, topic[0])
|
85
|
+
topic << data_points.collect { |r| [r[0], r[2] || 0] }
|
86
|
+
end
|
90
87
|
render :index
|
91
88
|
end
|
92
|
-
|
89
|
+
|
93
90
|
def litecache
|
94
|
-
@order
|
95
|
-
@topic =
|
91
|
+
@order ||= "rcount"
|
92
|
+
@topic = "Litecache"
|
96
93
|
@events = @lm.events_summaries(@topic, @resolution, @order, @dir, @search, @step * @count)
|
97
94
|
@events.each do |event|
|
98
|
-
data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event[
|
99
|
-
event[
|
100
|
-
event[
|
95
|
+
data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event["name"])
|
96
|
+
event["counts"] = data_points.collect { |r| [r["rtime"], r["rcount"]] }
|
97
|
+
event["values"] = data_points.collect { |r| [r["rtime"], r["ravg"]] }
|
101
98
|
end
|
102
99
|
@snapshot = read_snapshot(@topic)
|
103
|
-
@size =
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
@
|
109
|
-
|
110
|
-
|
111
|
-
|
100
|
+
@size = begin
|
101
|
+
@snapshot[0][:summary][:size]
|
102
|
+
rescue
|
103
|
+
0
|
104
|
+
end
|
105
|
+
@max_size = begin
|
106
|
+
@snapshot[0][:summary][:max_size]
|
107
|
+
rescue
|
108
|
+
0
|
109
|
+
end
|
110
|
+
@full = begin
|
111
|
+
(@size / @max_size) * 100
|
112
|
+
rescue
|
113
|
+
0
|
114
|
+
end
|
115
|
+
@entries = begin
|
116
|
+
@snapshot[0][:summary][:entries]
|
117
|
+
rescue
|
118
|
+
0
|
119
|
+
end
|
120
|
+
@gets = @events.find { |t| t["name"] == "get" }
|
121
|
+
@sets = @events.find { |t| t["name"] == "set" }
|
122
|
+
@reads = begin
|
123
|
+
@gets["rcount"]
|
124
|
+
rescue
|
125
|
+
0
|
126
|
+
end
|
127
|
+
@writes = begin
|
128
|
+
@sets["rcount"]
|
129
|
+
rescue
|
130
|
+
0
|
131
|
+
end
|
132
|
+
@hitrate = begin
|
133
|
+
@gets["ravg"]
|
134
|
+
rescue
|
135
|
+
0
|
136
|
+
end
|
112
137
|
@hits = @reads * @hitrate
|
113
138
|
@misses = @reads - @hits
|
114
|
-
@reads_vs_writes =
|
115
|
-
|
116
|
-
|
117
|
-
|
139
|
+
@reads_vs_writes = begin
|
140
|
+
@gets["counts"].collect.with_index { |obj, i| obj.clone << @sets["counts"][i][1] }
|
141
|
+
rescue
|
142
|
+
[]
|
143
|
+
end
|
144
|
+
@hits_vs_misses = begin
|
145
|
+
@gets["values"].collect.with_index { |obj, i| [obj[0], obj[1].to_f * @gets["counts"][i][1].to_f, (1 - obj[1].to_f) * @gets["counts"][i][1].to_f] }
|
146
|
+
rescue
|
147
|
+
[]
|
148
|
+
end
|
149
|
+
@top_reads = @lm.keys_summaries(@topic, "get", @resolution, @order, @dir, nil, @step * @count).first(8)
|
150
|
+
@top_writes = @lm.keys_summaries(@topic, "set", @resolution, @order, @dir, nil, @step * @count).first(8)
|
118
151
|
render :litecache
|
119
152
|
end
|
120
|
-
|
153
|
+
|
121
154
|
def litedb
|
122
|
-
@order
|
123
|
-
@topic =
|
155
|
+
@order ||= "rcount"
|
156
|
+
@topic = "Litedb"
|
124
157
|
@events = @lm.events_summaries(@topic, @resolution, @order, @dir, @search, @step * @count)
|
125
158
|
@events.each do |event|
|
126
|
-
data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event[
|
127
|
-
event[
|
128
|
-
event[
|
159
|
+
data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event["name"])
|
160
|
+
event["counts"] = data_points.collect { |r| [r["rtime"], r["rcount"] || 0] }
|
161
|
+
event["values"] = data_points.collect { |r| [r["rtime"], r["rtotal"] || 0] }
|
129
162
|
end
|
130
163
|
@snapshot = read_snapshot(@topic)
|
131
|
-
@size =
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
@
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
@
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
@
|
147
|
-
@
|
148
|
-
@
|
164
|
+
@size = begin
|
165
|
+
@snapshot[0][:summary][:size]
|
166
|
+
rescue
|
167
|
+
0
|
168
|
+
end
|
169
|
+
@tables = begin
|
170
|
+
@snapshot[0][:summary][:tables]
|
171
|
+
rescue
|
172
|
+
0
|
173
|
+
end
|
174
|
+
@indexes = begin
|
175
|
+
@snapshot[0][:summary][:indexes]
|
176
|
+
rescue
|
177
|
+
0
|
178
|
+
end
|
179
|
+
@gets = @events.find { |t| t["name"] == "Read" }
|
180
|
+
@sets = @events.find { |t| t["name"] == "Write" }
|
181
|
+
@reads = begin
|
182
|
+
@gets["rcount"]
|
183
|
+
rescue
|
184
|
+
0
|
185
|
+
end
|
186
|
+
@writes = begin
|
187
|
+
@sets["rcount"]
|
188
|
+
rescue
|
189
|
+
0
|
190
|
+
end
|
191
|
+
@time = begin
|
192
|
+
@gets["ravg"]
|
193
|
+
rescue
|
194
|
+
0
|
195
|
+
end
|
196
|
+
@reads_vs_writes = begin
|
197
|
+
@gets["counts"].collect.with_index { |obj, i| obj.clone << @sets["counts"][i][1] }
|
198
|
+
rescue
|
199
|
+
[]
|
200
|
+
end
|
201
|
+
@reads_vs_writes_times = begin
|
202
|
+
@gets["values"].collect.with_index { |obj, i| [obj[0], obj[1], @sets["values"][i][1].to_f] }
|
203
|
+
rescue
|
204
|
+
[]
|
205
|
+
end
|
206
|
+
@read_times = begin
|
207
|
+
@gets["rtotal"]
|
208
|
+
rescue
|
209
|
+
0
|
210
|
+
end
|
211
|
+
@write_times = begin
|
212
|
+
@sets["rtotal"]
|
213
|
+
rescue
|
214
|
+
0
|
215
|
+
end
|
216
|
+
@slowest = @lm.keys_summaries(@topic, "Read", @resolution, "ravg", "desc", nil, @step * @count).first(8)
|
217
|
+
@slowest += @lm.keys_summaries(@topic, "Write", @resolution, "ravg", "desc", nil, @step * @count).first(8)
|
218
|
+
@slowest = @slowest.sort_by { |a| a["ravg"] }.last(8).reverse
|
219
|
+
@popular = @lm.keys_summaries(@topic, "Read", @resolution, "rtotal", "desc", nil, @step * @count).first(8)
|
220
|
+
@popular += @lm.keys_summaries(@topic, "Write", @resolution, "rtotal", "desc", nil, @step * @count).first(8)
|
221
|
+
@popular = @popular.sort_by { |a| a["rtotal"] }.last(8).reverse
|
149
222
|
render :litedb
|
150
223
|
end
|
151
|
-
|
224
|
+
|
152
225
|
def litejob
|
153
|
-
@order
|
154
|
-
@topic =
|
226
|
+
@order ||= "rcount"
|
227
|
+
@topic = "Litejob"
|
155
228
|
@events = @lm.events_summaries(@topic, @resolution, @order, @dir, @search, @step * @count)
|
156
229
|
@events.each do |event|
|
157
|
-
data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event[
|
158
|
-
event[
|
159
|
-
event[
|
230
|
+
data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event["name"])
|
231
|
+
event["counts"] = data_points.collect { |r| [r["rtime"], r["rcount"] || 0] }
|
232
|
+
event["values"] = data_points.collect { |r| [r["rtime"], r["rtotal"] || 0] }
|
160
233
|
end
|
161
234
|
@snapshot = read_snapshot(@topic)
|
162
|
-
@size =
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
@
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
@
|
173
|
-
|
235
|
+
@size = begin
|
236
|
+
@snapshot[0][:summary][:size]
|
237
|
+
rescue
|
238
|
+
0
|
239
|
+
end
|
240
|
+
@jobs = begin
|
241
|
+
@snapshot[0][:summary][:jobs]
|
242
|
+
rescue
|
243
|
+
0
|
244
|
+
end
|
245
|
+
@queues = begin
|
246
|
+
@snapshot[0][:queues]
|
247
|
+
rescue
|
248
|
+
{}
|
249
|
+
end
|
250
|
+
@processed_jobs = @events.find { |e| e["name"] == "perform" }
|
251
|
+
@processed_count = begin
|
252
|
+
@processed_jobs["rcount"]
|
253
|
+
rescue
|
254
|
+
0
|
255
|
+
end
|
256
|
+
@processing_time = begin
|
257
|
+
@processed_jobs["rtotal"]
|
258
|
+
rescue
|
259
|
+
0
|
260
|
+
end
|
261
|
+
keys_summaries = @lm.keys_summaries(@topic, "perform", @resolution, "rcount", "desc", nil, @step * @count)
|
262
|
+
@processed_count_by_queue = keys_summaries.collect { |r| [r["key"], r["rcount"]] }
|
263
|
+
@processing_time_by_queue = keys_summaries.collect { |r| [r["key"], r["rtotal"]] } # .sort{|r1, r2| r1['rtotal'] > r2['rtotal'] }
|
264
|
+
@processed_count_over_time = begin
|
265
|
+
@events.find { |e| e["name"] == "perform" }["counts"]
|
266
|
+
rescue
|
267
|
+
[]
|
268
|
+
end
|
269
|
+
@processing_time_over_time = begin
|
270
|
+
@events.find { |e| e["name"] == "perform" }["values"]
|
271
|
+
rescue
|
272
|
+
[]
|
273
|
+
end
|
274
|
+
@processed_count_over_time_by_queues = []
|
174
275
|
@processing_time_over_time_by_queues = []
|
175
|
-
keys = [
|
176
|
-
keys_summaries.each_with_index do |summary,i|
|
177
|
-
key = summary[
|
276
|
+
keys = ["Time"]
|
277
|
+
keys_summaries.each_with_index do |summary, i|
|
278
|
+
key = summary["key"]
|
178
279
|
keys << key
|
179
|
-
data_points = @lm.key_data_points(@step, @count, @resolution, @topic,
|
280
|
+
data_points = @lm.key_data_points(@step, @count, @resolution, @topic, "perform", key)
|
180
281
|
if i == 0
|
181
|
-
data_points.each do |dp|
|
182
|
-
@processed_count_over_time_by_queues << [dp[
|
183
|
-
@processing_time_over_time_by_queues << [dp[
|
282
|
+
data_points.each do |dp|
|
283
|
+
@processed_count_over_time_by_queues << [dp["rtime"]]
|
284
|
+
@processing_time_over_time_by_queues << [dp["rtime"]]
|
184
285
|
end
|
185
286
|
end
|
186
287
|
data_points.each_with_index do |dp, j|
|
187
|
-
@processed_count_over_time_by_queues[j] << (dp[
|
188
|
-
@processing_time_over_time_by_queues[j] << (dp[
|
288
|
+
@processed_count_over_time_by_queues[j] << (dp["rcount"] || 0)
|
289
|
+
@processing_time_over_time_by_queues[j] << (dp["rtotal"] || 0)
|
189
290
|
end
|
190
291
|
end
|
191
292
|
@processed_count_over_time_by_queues.unshift(keys)
|
192
|
-
@processing_time_over_time_by_queues.unshift(keys)
|
293
|
+
@processing_time_over_time_by_queues.unshift(keys)
|
193
294
|
render :litejob
|
194
295
|
end
|
195
|
-
|
296
|
+
|
196
297
|
def litecable
|
197
|
-
@order
|
198
|
-
@topic =
|
298
|
+
@order ||= "rcount"
|
299
|
+
@topic = "Litecable"
|
199
300
|
@events = @lm.events_summaries(@topic, @resolution, @order, @dir, @search, @step * @count)
|
200
301
|
@events.each do |event|
|
201
|
-
data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event[
|
202
|
-
event[
|
302
|
+
data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event["name"])
|
303
|
+
event["counts"] = data_points.collect { |r| [r["rtime"], r["rcount"] || 0] }
|
304
|
+
end
|
305
|
+
|
306
|
+
@subscription_count = begin
|
307
|
+
@events.find { |t| t["name"] == "subscribe" }["rcount"]
|
308
|
+
rescue
|
309
|
+
0
|
310
|
+
end
|
311
|
+
@broadcast_count = begin
|
312
|
+
@events.find { |t| t["name"] == "broadcast" }["rcount"]
|
313
|
+
rescue
|
314
|
+
0
|
315
|
+
end
|
316
|
+
@message_count = begin
|
317
|
+
@events.find { |t| t["name"] == "message" }["rcount"]
|
318
|
+
rescue
|
319
|
+
0
|
203
320
|
end
|
204
321
|
|
205
|
-
@
|
206
|
-
|
207
|
-
|
322
|
+
@subscriptions_over_time = begin
|
323
|
+
@events.find { |t| t["name"] == "subscribe" }["counts"]
|
324
|
+
rescue
|
325
|
+
[]
|
326
|
+
end
|
327
|
+
@broadcasts_over_time = begin
|
328
|
+
@events.find { |t| t["name"] == "broadcast" }["counts"]
|
329
|
+
rescue
|
330
|
+
[]
|
331
|
+
end
|
332
|
+
@messages_over_time = begin
|
333
|
+
@events.find { |t| t["name"] == "message" }["counts"]
|
334
|
+
rescue
|
335
|
+
[]
|
336
|
+
end
|
337
|
+
@messages_over_time = @messages_over_time.collect.with_index { |msg, i| [msg[0], @broadcasts_over_time[i][1], msg[1]] }
|
208
338
|
|
209
|
-
@
|
210
|
-
@
|
211
|
-
@messages_over_time = @events.find{|t| t['name'] == 'message'}['counts'] rescue []
|
212
|
-
@messages_over_time = @messages_over_time.collect.with_index{|msg, i| [msg[0], @broadcasts_over_time[i][1], msg[1]]}
|
213
|
-
|
214
|
-
@top_subscribed_channels = @lm.keys_summaries(@topic, 'subscribe', @resolution, @order, @dir, @search, @step * @count).first(8)
|
215
|
-
@top_messaged_channels = @lm.keys_summaries(@topic, 'message', @resolution, @order, @dir, @search, @step * @count).first(8)
|
339
|
+
@top_subscribed_channels = @lm.keys_summaries(@topic, "subscribe", @resolution, @order, @dir, @search, @step * @count).first(8)
|
340
|
+
@top_messaged_channels = @lm.keys_summaries(@topic, "message", @resolution, @order, @dir, @search, @step * @count).first(8)
|
216
341
|
render :litecable
|
217
342
|
end
|
218
|
-
|
343
|
+
|
219
344
|
def index_url
|
220
345
|
"/?res=#{@res}&order=#{@order}&dir=#{@dir}&search=#{@search}"
|
221
346
|
end
|
222
|
-
|
347
|
+
|
223
348
|
def topic_url(topic)
|
224
349
|
"/topics/#{encode(topic)}?res=#{@res}&order=#{@order}&dir=#{@dir}&search=#{@search}"
|
225
350
|
end
|
@@ -227,58 +352,58 @@ class Liteboard
|
|
227
352
|
def index_sort_url(field)
|
228
353
|
"/?#{compose_query(field)}"
|
229
354
|
end
|
230
|
-
|
355
|
+
|
231
356
|
def topic_sort_url(field)
|
232
357
|
"/topics/#{encode(@topic)}?#{compose_query(field)}"
|
233
358
|
end
|
234
|
-
|
359
|
+
|
235
360
|
def event_sort_url(field)
|
236
361
|
"/topics/#{encode(@topic)}/events/#{encode(@event)}?#{compose_query(field)}"
|
237
362
|
end
|
238
|
-
|
363
|
+
|
239
364
|
def compose_query(field)
|
240
365
|
field.downcase!
|
241
|
-
"res=#{@res}&order=#{field}&dir=#{@order == field ? @idir : @dir}&search=#{@search}"
|
366
|
+
"res=#{@res}&order=#{field}&dir=#{(@order == field) ? @idir : @dir}&search=#{@search}"
|
242
367
|
end
|
243
|
-
|
368
|
+
|
244
369
|
def sorted?(field)
|
245
370
|
@order == field
|
246
371
|
end
|
247
|
-
|
372
|
+
|
248
373
|
def dir(field)
|
249
374
|
if sorted?(field)
|
250
|
-
if @dir ==
|
251
|
-
return "<span class='material-icons'>arrow_drop_up</span>"
|
375
|
+
if @dir == "asc"
|
376
|
+
return "<span class='material-icons'>arrow_drop_up</span>"
|
252
377
|
else
|
253
378
|
return "<span class='material-icons'>arrow_drop_down</span>"
|
254
379
|
end
|
255
380
|
end
|
256
|
-
|
381
|
+
" "
|
257
382
|
end
|
258
|
-
|
383
|
+
|
259
384
|
def encode(text)
|
260
385
|
URI.encode_uri_component(text)
|
261
386
|
end
|
262
|
-
|
387
|
+
|
263
388
|
def round(float)
|
264
389
|
return 0 unless float.is_a? Numeric
|
265
|
-
(
|
390
|
+
(float * 100).round.to_f / 100
|
266
391
|
end
|
267
|
-
|
392
|
+
|
268
393
|
def format(float)
|
269
394
|
string = float.to_s
|
270
|
-
whole, decimal = string.split(
|
271
|
-
whole = whole.
|
272
|
-
whole = [whole, decimal].join(
|
395
|
+
whole, decimal = string.split(".")
|
396
|
+
whole = whole.chars.reverse.each_slice(3).map(&:join).join(",").reverse
|
397
|
+
whole = [whole, decimal].join(".") if decimal
|
273
398
|
whole
|
274
399
|
end
|
275
|
-
|
400
|
+
|
276
401
|
def self.app
|
277
|
-
|
402
|
+
@@app
|
278
403
|
end
|
279
404
|
|
280
405
|
private
|
281
|
-
|
406
|
+
|
282
407
|
def read_snapshot(topic)
|
283
408
|
snapshot = @lm.snapshot(topic)
|
284
409
|
if snapshot.empty?
|
@@ -286,20 +411,15 @@ class Liteboard
|
|
286
411
|
else
|
287
412
|
snapshot[0] = Oj.load(snapshot[0]) unless snapshot[0].nil?
|
288
413
|
end
|
289
|
-
snapshot
|
414
|
+
snapshot
|
290
415
|
end
|
291
|
-
|
416
|
+
|
292
417
|
def render(tpl_name)
|
293
418
|
layout = Tilt.new("#{__dir__}/views/layout.erb")
|
294
|
-
tpl_path = "#{__dir__}/views/#{tpl_name
|
419
|
+
tpl_path = "#{__dir__}/views/#{tpl_name}.erb"
|
295
420
|
tpl = Tilt.new(tpl_path)
|
296
|
-
|
421
|
+
layout.render(self) { tpl.render(self) }
|
297
422
|
end
|
298
|
-
|
299
|
-
|
300
423
|
end
|
301
424
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
#Rack::Server.start({app: Litebaord.app, daemonize: false})
|
425
|
+
# Rack::Server.start({app: Litebaord.app, daemonize: false})
|