groonga-client-model 0.9.5 → 0.9.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/text/news.md +8 -0
- data/lib/groonga_client_model/client.rb +15 -1
- data/lib/groonga_client_model/log_subscriber.rb +90 -0
- data/lib/groonga_client_model/railtie.rb +7 -0
- data/lib/groonga_client_model/railties/controller_runtime.rb +56 -0
- data/lib/groonga_client_model/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69aeb3216e670c96bb30d59565e4aab119267d6e
|
4
|
+
data.tar.gz: c30ae60d4a6ae6dc644aa01b3db6079dc8bb257f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6849d586cfa69b14047ddccc392db40cb4545a232d69b8df7d59163549d3ac04948064aa6b07cf6b2333a851143f8c444b644e7fb17472c26a055913dd0bc02b
|
7
|
+
data.tar.gz: f765054cdca37447290b1d5dfbd05a6406df40a4b30af4a7c187e406f99aec18b8a99239563ab9a578b342512e87f1789e4c4f81ada50ec438dd96babc5b722b
|
data/doc/text/news.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2016 Kouhei Sutou <kou@clear-code.com>
|
1
|
+
# Copyright (C) 2016-2017 Kouhei Sutou <kou@clear-code.com>
|
2
2
|
#
|
3
3
|
# This library is free software; you can redistribute it and/or
|
4
4
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -31,8 +31,22 @@ module GroongaClientModel
|
|
31
31
|
|
32
32
|
def open
|
33
33
|
Groonga::Client.open(url: @url) do |client|
|
34
|
+
client.extend(Notifiable)
|
34
35
|
yield(client)
|
35
36
|
end
|
36
37
|
end
|
38
|
+
|
39
|
+
module Notifiable
|
40
|
+
private
|
41
|
+
def execute_command(command, &block)
|
42
|
+
name = "groonga.groonga_client_model"
|
43
|
+
payload = {
|
44
|
+
:command => command,
|
45
|
+
}
|
46
|
+
ActiveSupport::Notifications.instrument(name, payload) do
|
47
|
+
super(command, &block)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
37
51
|
end
|
38
52
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# Copyright (C) 2017 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
module GroongaClientModel
|
18
|
+
class LogSubscriber < ActiveSupport::LogSubscriber
|
19
|
+
if respond_to?(:thread_cattr_accessor)
|
20
|
+
thread_cattr_accessor :runtime, instance_accessor: false
|
21
|
+
else
|
22
|
+
# For ActiveSupport < 5
|
23
|
+
class << self
|
24
|
+
def runtime
|
25
|
+
Thread.current["groonga_client_model.log_subscriber.runtime"]
|
26
|
+
end
|
27
|
+
|
28
|
+
def runtime=(value)
|
29
|
+
Thread.current["groonga_client_model.log_subscriber.runtime"] = value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class << self
|
35
|
+
def reset_runtime
|
36
|
+
self.runtime = 0.0
|
37
|
+
end
|
38
|
+
|
39
|
+
def measure
|
40
|
+
before_runtime = runtime
|
41
|
+
yield
|
42
|
+
runtime - before_runtime
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def groonga(event)
|
47
|
+
self.class.runtime += event.duration
|
48
|
+
|
49
|
+
debug do
|
50
|
+
command = event.payload[:command]
|
51
|
+
|
52
|
+
title = color("#{command.command_name} (#{event.duration.round(1)}ms)",
|
53
|
+
title_color(command),
|
54
|
+
true)
|
55
|
+
formatted_command = color(command.to_command_format,
|
56
|
+
command_color(command),
|
57
|
+
true)
|
58
|
+
" #{title} #{formatted_command}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
def title_color(command)
|
64
|
+
if command.command_name == "select"
|
65
|
+
MAGENTA
|
66
|
+
else
|
67
|
+
CYAN
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def command_color(command)
|
72
|
+
case command.command_name
|
73
|
+
when "select"
|
74
|
+
BLUE
|
75
|
+
when "load"
|
76
|
+
GREEN
|
77
|
+
when "delete"
|
78
|
+
RED
|
79
|
+
else
|
80
|
+
MAGENTA
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def logger
|
85
|
+
GroongaClientModel.logger
|
86
|
+
end
|
87
|
+
|
88
|
+
attach_to :groonga_client_model
|
89
|
+
end
|
90
|
+
end
|
@@ -44,6 +44,13 @@ module GroongaClientModel
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
initializer "groonga_client_model.log_runtime" do
|
48
|
+
require "groonga_client_model/railties/controller_runtime"
|
49
|
+
ActiveSupport.on_load(:action_controller) do
|
50
|
+
include GroongaClientModel::Railties::ControllerRuntime
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
47
54
|
initializer "groonga_client_model.set_configs" do |app|
|
48
55
|
ActiveSupport.on_load(:groonga_client_model) do
|
49
56
|
app.config.groonga_client_model.each do |key, value|
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# Copyright (C) 2017 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
require "groonga_client_model/log_subscriber"
|
18
|
+
|
19
|
+
module GroongaClientModel
|
20
|
+
module Railties
|
21
|
+
module ControllerRuntime
|
22
|
+
extend ActiveSupport::Concern
|
23
|
+
|
24
|
+
attr_internal :groonga_runtime
|
25
|
+
|
26
|
+
def process_action(action, *args)
|
27
|
+
GroongaClientModel::LogSubscriber.reset_runtime
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
31
|
+
def cleanup_view_runtime
|
32
|
+
total_runtime = nil
|
33
|
+
groonga_runtime_in_view = GroongaClientModel::LogSubscriber.measure do
|
34
|
+
total_runtime = super
|
35
|
+
end
|
36
|
+
total_runtime - groonga_runtime_in_view
|
37
|
+
end
|
38
|
+
|
39
|
+
def append_info_to_payload(payload)
|
40
|
+
super
|
41
|
+
payload[:groonga_runtime] = GroongaClientModel::LogSubscriber.runtime
|
42
|
+
end
|
43
|
+
|
44
|
+
module ClassMethods
|
45
|
+
def log_process_action(payload)
|
46
|
+
messages = super
|
47
|
+
groonga_runtime = payload[:groonga_runtime]
|
48
|
+
if groonga_runtime
|
49
|
+
messages << ("Groonga: %.1fms" % groonga_runtime.to_f)
|
50
|
+
end
|
51
|
+
messages
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groonga-client-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouhei Sutou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: groonga-client
|
@@ -142,9 +142,11 @@ files:
|
|
142
142
|
- lib/groonga_client_model/client_opener.rb
|
143
143
|
- lib/groonga_client_model/error.rb
|
144
144
|
- lib/groonga_client_model/load_value_generator.rb
|
145
|
+
- lib/groonga_client_model/log_subscriber.rb
|
145
146
|
- lib/groonga_client_model/modelizable.rb
|
146
147
|
- lib/groonga_client_model/modelize.rb
|
147
148
|
- lib/groonga_client_model/railtie.rb
|
149
|
+
- lib/groonga_client_model/railties/controller_runtime.rb
|
148
150
|
- lib/groonga_client_model/railties/groonga.rake
|
149
151
|
- lib/groonga_client_model/record.rb
|
150
152
|
- lib/groonga_client_model/schema.rb
|