taps 0.2.11 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION.yml +1 -1
- data/lib/taps/client_session.rb +3 -3
- data/lib/taps/db_session.rb +42 -6
- data/lib/taps/server.rb +3 -3
- metadata +5 -5
data/VERSION.yml
CHANGED
data/lib/taps/client_session.rb
CHANGED
@@ -118,8 +118,8 @@ class ClientSession
|
|
118
118
|
db.tables.each do |table_name|
|
119
119
|
table = db[table_name]
|
120
120
|
count = table.count
|
121
|
-
|
122
|
-
order =
|
121
|
+
primary_key = db.primary_key(table_name.to_sym)
|
122
|
+
order = primary_key ? [primary_key.to_sym] : table.columns
|
123
123
|
chunksize = self.default_chunksize
|
124
124
|
|
125
125
|
progress = ProgressBar.new(table_name.to_s, count)
|
@@ -128,7 +128,7 @@ class ClientSession
|
|
128
128
|
loop do
|
129
129
|
row_size = 0
|
130
130
|
chunksize = Taps::Utils.calculate_chunksize(chunksize) do |c|
|
131
|
-
rows = Taps::Utils.format_data(table.order(order).limit(c, offset).all)
|
131
|
+
rows = Taps::Utils.format_data(table.order(*order).limit(c, offset).all)
|
132
132
|
break if rows == { }
|
133
133
|
|
134
134
|
row_size = rows[:data].size
|
data/lib/taps/db_session.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'thread'
|
2
|
+
|
1
3
|
Sequel::Model.db = Sequel.connect(Taps::Config.taps_database_url)
|
2
4
|
|
3
5
|
class DbSession < Sequel::Model
|
@@ -9,17 +11,51 @@ class DbSession < Sequel::Model
|
|
9
11
|
timestamp :last_access
|
10
12
|
end
|
11
13
|
|
14
|
+
@@connections = {}
|
15
|
+
@@mutex = Mutex.new
|
16
|
+
|
12
17
|
def connection
|
13
|
-
@@
|
14
|
-
|
18
|
+
@@mutex.synchronize {
|
19
|
+
conn =
|
20
|
+
if @@connections.key?(key)
|
21
|
+
@@connections[key].first
|
22
|
+
else
|
23
|
+
Sequel.connect(database_url)
|
24
|
+
end
|
25
|
+
@@connections[key] = [conn, Time.now]
|
26
|
+
return conn
|
27
|
+
}
|
15
28
|
end
|
16
29
|
|
17
30
|
def disconnect
|
18
|
-
|
19
|
-
@@connections
|
20
|
-
|
21
|
-
|
31
|
+
@@mutex.synchronize {
|
32
|
+
if @@connections.key?(key)
|
33
|
+
conn, time = @@connections.delete(key)
|
34
|
+
conn.disconnect
|
35
|
+
end
|
36
|
+
}
|
22
37
|
end
|
38
|
+
|
39
|
+
# Removes connections that have not been accessed within the
|
40
|
+
# past thirty seconds.
|
41
|
+
def self.cleanup
|
42
|
+
@@mutex.synchronize {
|
43
|
+
now = Time.now
|
44
|
+
@@connections.each do |key, (conn, time)|
|
45
|
+
if now - time > 30
|
46
|
+
@@connections.delete(key)
|
47
|
+
conn.disconnect
|
48
|
+
end
|
49
|
+
end
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
Thread.new {
|
54
|
+
while true
|
55
|
+
sleep 30
|
56
|
+
cleanup
|
57
|
+
end
|
58
|
+
}.run
|
23
59
|
end
|
24
60
|
|
25
61
|
DbSession.create_table! unless DbSession.table_exists?
|
data/lib/taps/server.rb
CHANGED
@@ -117,9 +117,9 @@ class Server < Sinatra::Default
|
|
117
117
|
|
118
118
|
db = session.connection
|
119
119
|
table = db[params[:table].to_sym]
|
120
|
-
|
121
|
-
order =
|
122
|
-
raw_data = Marshal.dump(Taps::Utils.format_data(table.order(order).limit(chunk, offset).all))
|
120
|
+
primary_key = db.primary_key(params[:table].to_sym)
|
121
|
+
order = primary_key ? [primary_key.to_sym] : table.columns
|
122
|
+
raw_data = Marshal.dump(Taps::Utils.format_data(table.order(*order).limit(chunk, offset).all))
|
123
123
|
gzip_data = Taps::Utils.gzip(raw_data)
|
124
124
|
response['Taps-Checksum'] = Taps::Utils.checksum(gzip_data).to_s
|
125
125
|
response['Content-Type'] = "application/octet-stream"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Chimal, Jr.
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-03-
|
13
|
+
date: 2009-03-31 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -88,17 +88,17 @@ files:
|
|
88
88
|
- spec/server_spec.rb
|
89
89
|
- spec/client_session_spec.rb
|
90
90
|
- spec/utils_spec.rb
|
91
|
-
- lib/taps/db_session.rb
|
92
91
|
- lib/taps/progress_bar.rb
|
93
92
|
- lib/taps/client_session.rb
|
93
|
+
- lib/taps/server.rb
|
94
|
+
- lib/taps/utils.rb
|
94
95
|
- lib/taps/adapter_hacks.rb
|
95
96
|
- lib/taps/adapter_hacks/invalid_text_limit.rb
|
96
97
|
- lib/taps/adapter_hacks/non_rails_schema_dump.rb
|
97
98
|
- lib/taps/schema.rb
|
98
99
|
- lib/taps/config.rb
|
99
100
|
- lib/taps/cli.rb
|
100
|
-
- lib/taps/
|
101
|
-
- lib/taps/utils.rb
|
101
|
+
- lib/taps/db_session.rb
|
102
102
|
- README.rdoc
|
103
103
|
- LICENSE
|
104
104
|
- VERSION.yml
|