arangorb 1.2.0 → 1.3.0
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.
- checksums.yaml +4 -4
- data/ArangoRB.gemspec +18 -18
- data/Gemfile +8 -7
- data/LICENSE +21 -21
- data/README.md +906 -867
- data/lib/ArangoRB_AQL.rb +181 -160
- data/lib/ArangoRB_Cache.rb +174 -174
- data/lib/ArangoRB_Col.rb +526 -499
- data/lib/ArangoRB_DB.rb +363 -339
- data/lib/ArangoRB_Doc.rb +319 -298
- data/lib/ArangoRB_Edg.rb +184 -169
- data/lib/ArangoRB_Gra.rb +201 -180
- data/lib/ArangoRB_Index.rb +135 -115
- data/lib/ArangoRB_Replication.rb +261 -0
- data/lib/ArangoRB_Ser.rb +446 -441
- data/lib/ArangoRB_Task.rb +129 -113
- data/lib/ArangoRB_Tra.rb +169 -142
- data/lib/ArangoRB_Tran.rb +68 -53
- data/lib/ArangoRB_User.rb +149 -136
- data/lib/ArangoRB_Ver.rb +162 -147
- data/lib/arangorb.rb +16 -15
- data/spec/arangoRB_helper.rb +4 -4
- data/spec/arangoRestart_helper.rb +14 -14
- data/spec/lib/0.1.0/arangoAQL_helper.rb +64 -64
- data/spec/lib/0.1.0/arangoC_helper.rb +170 -170
- data/spec/lib/0.1.0/arangoDB_helper.rb +119 -119
- data/spec/lib/0.1.0/arangoDoc_helper.rb +79 -79
- data/spec/lib/0.1.0/arangoE_helper.rb +50 -50
- data/spec/lib/0.1.0/arangoG_helper.rb +78 -78
- data/spec/lib/0.1.0/arangoS_helper.rb +37 -37
- data/spec/lib/0.1.0/arangoT_helper.rb +48 -48
- data/spec/lib/0.1.0/arangoV_helper.rb +65 -65
- data/spec/lib/1.0.0/arangoC_helper.rb +73 -73
- data/spec/lib/1.0.0/arangoDB_helper.rb +48 -48
- data/spec/lib/1.0.0/arangoI_helper.rb +43 -43
- data/spec/lib/1.0.0/arangoS_helper.rb +192 -192
- data/spec/lib/1.0.0/arangoTa_helper.rb +49 -49
- data/spec/lib/1.0.0/arangoTr_helper.rb +15 -15
- data/spec/lib/1.0.0/arangoU_helper.rb +72 -72
- data/spec/lib/1.1.0/arangoRB_helper.rb +144 -144
- data/spec/lib/1.1.0/arangoRB_walks_helper.rb +19 -19
- data/spec/lib/1.2.0/arangoCache_helper.rb +66 -66
- data/spec/lib/1.3.0/arangoHash_helper.rb +30 -0
- data/spec/lib/arangoRB_0.1.0_helper.rb +9 -9
- data/spec/lib/arangoRB_1.0.0_helper.rb +6 -6
- data/spec/lib/arangoRB_1.1.0_helper.rb +2 -2
- data/spec/lib/arangoRB_1.2.0_helper.rb +2 -1
- data/spec/spec_helper.rb +41 -41
- metadata +6 -5
data/lib/ArangoRB_AQL.rb
CHANGED
@@ -1,160 +1,181 @@
|
|
1
|
-
# === AQL ===
|
2
|
-
|
3
|
-
class ArangoAQL < ArangoServer
|
4
|
-
def initialize(query: nil, batchSize: nil, ttl: nil, cache: nil, options: nil, bindVars: nil, database: @@database) # TESTED
|
5
|
-
if query.is_a?(String)
|
6
|
-
@query = query
|
7
|
-
elsif query.is_a?(ArangoAQL)
|
8
|
-
@query = query.query
|
9
|
-
else
|
10
|
-
raise "query should be String or ArangoAQL instance, not a #{query.class}"
|
11
|
-
end
|
12
|
-
|
13
|
-
if database.is_a?(String)
|
14
|
-
@database = database
|
15
|
-
elsif database.is_a?(ArangoDatabase)
|
16
|
-
@database = database.database
|
17
|
-
else
|
18
|
-
raise "databaseshould be String or ArangoDatabase instance, not a #{database.class}"
|
19
|
-
end
|
20
|
-
|
21
|
-
@batchSize = batchSize
|
22
|
-
@ttl = ttl
|
23
|
-
@cache = cache
|
24
|
-
@options = options
|
25
|
-
@bindVars = bindVars
|
26
|
-
|
27
|
-
@count =
|
28
|
-
@
|
29
|
-
@
|
30
|
-
@
|
31
|
-
@
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
alias size
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
"
|
50
|
-
"
|
51
|
-
"batchSize" => @batchSize,
|
52
|
-
"
|
53
|
-
"
|
54
|
-
"
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
"
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
def
|
156
|
-
|
157
|
-
result
|
158
|
-
|
159
|
-
|
160
|
-
|
1
|
+
# === AQL ===
|
2
|
+
|
3
|
+
class ArangoAQL < ArangoServer
|
4
|
+
def initialize(query: nil, batchSize: nil, ttl: nil, cache: nil, options: nil, bindVars: nil, database: @@database) # TESTED
|
5
|
+
if query.is_a?(String)
|
6
|
+
@query = query
|
7
|
+
elsif query.is_a?(ArangoAQL)
|
8
|
+
@query = query.query
|
9
|
+
else
|
10
|
+
raise "query should be String or ArangoAQL instance, not a #{query.class}"
|
11
|
+
end
|
12
|
+
|
13
|
+
if database.is_a?(String)
|
14
|
+
@database = database
|
15
|
+
elsif database.is_a?(ArangoDatabase)
|
16
|
+
@database = database.database
|
17
|
+
else
|
18
|
+
raise "databaseshould be String or ArangoDatabase instance, not a #{database.class}"
|
19
|
+
end
|
20
|
+
|
21
|
+
@batchSize = batchSize
|
22
|
+
@ttl = ttl
|
23
|
+
@cache = cache
|
24
|
+
@options = options
|
25
|
+
@bindVars = bindVars
|
26
|
+
|
27
|
+
@count = true
|
28
|
+
@quantity = nil
|
29
|
+
@hasMore = false
|
30
|
+
@id = ""
|
31
|
+
@result = []
|
32
|
+
@idCache = "AQL_#{@query}"
|
33
|
+
end
|
34
|
+
|
35
|
+
attr_accessor :count, :query, :batchSize, :ttl, :cache, :options, :bindVars, :quantity
|
36
|
+
attr_reader :hasMore, :id, :result, :idCache
|
37
|
+
alias size batchSize
|
38
|
+
alias size= batchSize=
|
39
|
+
|
40
|
+
# === RETRIEVE ===
|
41
|
+
|
42
|
+
def to_hash
|
43
|
+
{
|
44
|
+
"query" => @query,
|
45
|
+
"database" => @database,
|
46
|
+
"result" => @result.map{|x| x.is_a?(ArangoServer) ? x.to_h : x},
|
47
|
+
"count" => @count,
|
48
|
+
"quantity" => @quantity,
|
49
|
+
"ttl" => @ttl,
|
50
|
+
"cache" => @cache,
|
51
|
+
"batchSize" => @batchSize,
|
52
|
+
"bindVars" => @bindVars,
|
53
|
+
"options" => @options,
|
54
|
+
"idCache" => @idCache,
|
55
|
+
}.delete_if{|k,v| v.nil?}
|
56
|
+
end
|
57
|
+
alias to_h to_hash
|
58
|
+
|
59
|
+
def database
|
60
|
+
ArangoDatabase.new(database: @database)
|
61
|
+
end
|
62
|
+
|
63
|
+
# === EXECUTE QUERY ===
|
64
|
+
|
65
|
+
def execute # TESTED
|
66
|
+
body = {
|
67
|
+
"query" => @query,
|
68
|
+
"count" => count,
|
69
|
+
"batchSize" => @batchSize,
|
70
|
+
"ttl" => @ttl,
|
71
|
+
"cache" => @cache,
|
72
|
+
"options" => @options,
|
73
|
+
"bindVars" => @bindVars
|
74
|
+
}.delete_if{|k,v| v.nil?}
|
75
|
+
request = @@request.merge({ :body => body.to_json })
|
76
|
+
result = self.class.post("/_db/#{@database}/_api/cursor", request)
|
77
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
78
|
+
return true if @@async
|
79
|
+
result = result.parsed_response
|
80
|
+
return @@verbose ? result : result["errorMessage"] if result["error"]
|
81
|
+
@quantity = result["count"]
|
82
|
+
@hasMore = result["hasMore"]
|
83
|
+
@id = result["id"]
|
84
|
+
if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key"))
|
85
|
+
@result = result["result"]
|
86
|
+
else
|
87
|
+
@result = result["result"].map{|x| ArangoDocument.new(key: x["_key"], collection: x["_id"].split("/")[0], database: @database, body: x)}
|
88
|
+
end
|
89
|
+
return @@verbose ? result : self
|
90
|
+
end
|
91
|
+
|
92
|
+
def next # TESTED
|
93
|
+
unless @hasMore
|
94
|
+
print "No other results"
|
95
|
+
else
|
96
|
+
result = self.class.put("/_db/#{@database}/_api/cursor/#{@id}", @@request)
|
97
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
98
|
+
return true if @@async
|
99
|
+
result = result.parsed_response
|
100
|
+
return @@verbose ? result : result["errorMessage"] if result["error"]
|
101
|
+
@count = result["count"]
|
102
|
+
@hasMore = result["hasMore"]
|
103
|
+
@id = result["id"]
|
104
|
+
if(result["result"][0].nil? || !result["result"][0].is_a?(Hash) || !result["result"][0].key?("_key"))
|
105
|
+
@result = result["result"]
|
106
|
+
else
|
107
|
+
@result = result["result"].map{|x| ArangoDocument.new(key: x["_key"], collection: x["_id"].split("/")[0], database: @database, body: x)}
|
108
|
+
end
|
109
|
+
return @@verbose ? result : self
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# === PROPERTY QUERY ===
|
114
|
+
|
115
|
+
def explain # TESTED
|
116
|
+
body = {
|
117
|
+
"query" => @query,
|
118
|
+
"options" => @options,
|
119
|
+
"bindVars" => @bindVars
|
120
|
+
}.delete_if{|k,v| v.nil?}
|
121
|
+
request = @@request.merge({ :body => body.to_json })
|
122
|
+
result = self.class.post("/_db/#{@database}/_api/explain", request)
|
123
|
+
return_result result: result
|
124
|
+
end
|
125
|
+
|
126
|
+
def parse # TESTED
|
127
|
+
body = { "query" => @query }
|
128
|
+
request = @@request.merge({ :body => body.to_json })
|
129
|
+
result = self.class.post("/_db/#{@database}/_api/query", request)
|
130
|
+
return_result result: result
|
131
|
+
end
|
132
|
+
|
133
|
+
def properties # TESTED
|
134
|
+
result = self.class.get("/_db/#{@database}/_api/query/properties", @@request)
|
135
|
+
return_result result: result
|
136
|
+
end
|
137
|
+
|
138
|
+
def current # TESTED
|
139
|
+
result = self.class.get("/_db/#{@database}/_api/query/current", @@request)
|
140
|
+
return_result result: result
|
141
|
+
end
|
142
|
+
|
143
|
+
def slow # TESTED
|
144
|
+
result = self.class.get("/_db/#{@database}/_api/query/slow", @@request)
|
145
|
+
return_result result: result
|
146
|
+
end
|
147
|
+
|
148
|
+
# === DELETE ===
|
149
|
+
|
150
|
+
def stopSlow # TESTED
|
151
|
+
result = self.class.delete("/_db/#{@database}/_api/query/slow", @@request)
|
152
|
+
return_result result: result, caseTrue: true
|
153
|
+
end
|
154
|
+
|
155
|
+
def kill(id: @id) # TESTED
|
156
|
+
result = self.class.delete("/_db/#{@database}/_api/query/#{id}", @@request)
|
157
|
+
return_result result: result, caseTrue: true
|
158
|
+
end
|
159
|
+
|
160
|
+
def changeProperties(slowQueryThreshold: nil, enabled: nil, maxSlowQueries: nil, trackSlowQueries: nil, maxQueryStringLength: nil) # TESTED
|
161
|
+
body = {
|
162
|
+
"slowQueryThreshold" => slowQueryThreshold,
|
163
|
+
"enabled" => enabled,
|
164
|
+
"maxSlowQueries" => maxSlowQueries,
|
165
|
+
"trackSlowQueries" => trackSlowQueries,
|
166
|
+
"maxQueryStringLength" => maxQueryStringLength
|
167
|
+
}.delete_if{|k,v| v.nil?}
|
168
|
+
request = @@request.merge({ :body => body.to_json })
|
169
|
+
result = self.class.put("/_db/#{@database}/_api/query/properties", request)
|
170
|
+
return_result result: result
|
171
|
+
end
|
172
|
+
|
173
|
+
# === UTILITY ===
|
174
|
+
|
175
|
+
def return_result(result:, caseTrue: false)
|
176
|
+
return result.headers["x-arango-async-id"] if @@async == "store"
|
177
|
+
return true if @@async
|
178
|
+
result = result.parsed_response
|
179
|
+
@@verbose ? result : (result.is_a?(Hash) && result["error"]) ? result["errorMessage"] : caseTrue ? true : result
|
180
|
+
end
|
181
|
+
end
|
data/lib/ArangoRB_Cache.rb
CHANGED
@@ -1,174 +1,174 @@
|
|
1
|
-
# ==== CACHE ====
|
2
|
-
|
3
|
-
class ArangoCache
|
4
|
-
@max = {
|
5
|
-
"Database" => 1,
|
6
|
-
"Collection" => 20,
|
7
|
-
"Document" => 200,
|
8
|
-
"Graph" => 1,
|
9
|
-
"Vertex" => 50,
|
10
|
-
"Edge" => 100,
|
11
|
-
"Index" => 20,
|
12
|
-
"AQL" => 100,
|
13
|
-
"User" => 50,
|
14
|
-
"Task" => 20,
|
15
|
-
"Traversal" => 20,
|
16
|
-
"Transaction" => 20,
|
17
|
-
"Other" => 100
|
18
|
-
}
|
19
|
-
@cache = {
|
20
|
-
"Database" => {},
|
21
|
-
"Collection" => {},
|
22
|
-
"Document" => {},
|
23
|
-
"Graph" => {},
|
24
|
-
"Vertex" => {},
|
25
|
-
"Edge" => {},
|
26
|
-
"Index" => {},
|
27
|
-
"AQL" => {},
|
28
|
-
"User" => {},
|
29
|
-
"Task" => {},
|
30
|
-
"Traversal" => {},
|
31
|
-
"Transaction" => {},
|
32
|
-
"Other" => {}
|
33
|
-
}
|
34
|
-
|
35
|
-
class << self
|
36
|
-
attr_accessor :max
|
37
|
-
|
38
|
-
def max(type:, val:)
|
39
|
-
return nil if @max[type].nil?
|
40
|
-
while @cache[type].length > val
|
41
|
-
@cache[type].shift
|
42
|
-
end
|
43
|
-
@max[type] = val
|
44
|
-
end
|
45
|
-
|
46
|
-
def retrieve
|
47
|
-
@cache
|
48
|
-
end
|
49
|
-
|
50
|
-
def cache(id: nil, data:)
|
51
|
-
val_to_cache = []
|
52
|
-
data = [data] unless data.is_a? Array
|
53
|
-
|
54
|
-
if id.nil?
|
55
|
-
data.each do |d|
|
56
|
-
type = d.class.to_s
|
57
|
-
type.slice! "Arango"
|
58
|
-
if @max[type].nil?
|
59
|
-
type = "Other"
|
60
|
-
idCache = "OTH_#{d.class.to_s}_#{Random.rand(10^12)}"
|
61
|
-
else
|
62
|
-
idCache = d.idCache
|
63
|
-
end
|
64
|
-
val_to_cache << [type, idCache, d]
|
65
|
-
end
|
66
|
-
else
|
67
|
-
id = [id] unless id.is_a? Array
|
68
|
-
if data.length == id.length
|
69
|
-
for i in 0...id.length
|
70
|
-
type = data[i].class.to_s
|
71
|
-
type.slice! "Arango"
|
72
|
-
type = "Other" if @max[type].nil?
|
73
|
-
val_to_cache << [type, id[i], data[i]]
|
74
|
-
end
|
75
|
-
else
|
76
|
-
return "Id should be a String or an Array with the same size of the Data Array"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
val_to_cache.each do |val|
|
81
|
-
@cache[val[0]][val[1]] = val[2]
|
82
|
-
@cache[val[0]].shift if @cache[val[0]].length > @max[val[0]]
|
83
|
-
end
|
84
|
-
|
85
|
-
val_to_cache
|
86
|
-
end
|
87
|
-
|
88
|
-
def uncache(type: nil, id: nil, data: nil)
|
89
|
-
if id.nil? && data.nil? && !type.nil?
|
90
|
-
val_to_uncache = @cache[type].map{|k,v| v}
|
91
|
-
val_to_uncache = val_to_uncache[0] if val_to_uncache.length == 1
|
92
|
-
return val_to_uncache
|
93
|
-
end
|
94
|
-
|
95
|
-
val_to_uncache = []
|
96
|
-
unless data.nil?
|
97
|
-
data = [data] unless data.is_a? Array
|
98
|
-
data.each do |d|
|
99
|
-
type = d.class.to_s
|
100
|
-
type.slice! "Arango"
|
101
|
-
next if @max[type].nil? || type == "Other"
|
102
|
-
idCache = d.idCache
|
103
|
-
val_to_uncache << [type, idCache]
|
104
|
-
end
|
105
|
-
end
|
106
|
-
unless type.nil? || id.nil?
|
107
|
-
id = [id] unless id.is_a? Array
|
108
|
-
if type.is_a? Array
|
109
|
-
if type.length == id.length
|
110
|
-
for i in 0...type.length
|
111
|
-
val_to_uncache << [type[i], id[i]]
|
112
|
-
end
|
113
|
-
else
|
114
|
-
return "Type should be a String or an Array with the same size of the Id Array"
|
115
|
-
end
|
116
|
-
elsif type.is_a? String
|
117
|
-
id.each do |idCache|
|
118
|
-
val_to_uncache << [type, idCache]
|
119
|
-
end
|
120
|
-
else
|
121
|
-
return "Type should be a String or an Array with the same size of the Id Array"
|
122
|
-
end
|
123
|
-
end
|
124
|
-
val_to_uncache = val_to_uncache.map{|val| @cache[val[0]][val[1]]}
|
125
|
-
val_to_uncache = val_to_uncache[0] if val_to_uncache.length == 1
|
126
|
-
val_to_uncache
|
127
|
-
end
|
128
|
-
|
129
|
-
def clear(type: nil, id: nil, data: nil)
|
130
|
-
if type.nil? && id.nil? && data.nil?
|
131
|
-
@cache = { "Database" => {}, "Collection" => {}, "Document" => {}, "Graph" => {}, "Vertex" => {}, "Edge" => {}, "Index" => {}, "Query" => {},"User" => {}, "Traversal" => {}, "Transaction" => {} }
|
132
|
-
return true
|
133
|
-
end
|
134
|
-
|
135
|
-
if !type.nil? && id.nil? && data.nil?
|
136
|
-
@cache[type] = {}
|
137
|
-
return true
|
138
|
-
end
|
139
|
-
|
140
|
-
val_to_clear = []
|
141
|
-
unless data.nil?
|
142
|
-
data = [data] unless data.is_a? Array
|
143
|
-
data.each do |d|
|
144
|
-
type = d.class.to_s
|
145
|
-
type.slice! "Arango"
|
146
|
-
next if @max[type].nil? || type == "Other"
|
147
|
-
val_to_clear << [type, d.idCache]
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
unless type.nil? || id.nil?
|
152
|
-
id = [id] unless id.is_a? Array
|
153
|
-
if type.is_a? Array
|
154
|
-
if type.length == id.length
|
155
|
-
for i in 0...type.length
|
156
|
-
val_to_clear << [type[i], id[i]]
|
157
|
-
end
|
158
|
-
else
|
159
|
-
return "Type should be a String or an Array with the same size of the Id Array"
|
160
|
-
end
|
161
|
-
elsif type.is_a? String
|
162
|
-
id.each do |idCache|
|
163
|
-
val_to_clear << [type, idCache]
|
164
|
-
end
|
165
|
-
else
|
166
|
-
return "Type should be a String or an Array with the same size of the Id Array"
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
val_to_clear.each{|val| @cache[val[0]].delete(val[1])}
|
171
|
-
true
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
1
|
+
# ==== CACHE ====
|
2
|
+
|
3
|
+
class ArangoCache
|
4
|
+
@max = {
|
5
|
+
"Database" => 1,
|
6
|
+
"Collection" => 20,
|
7
|
+
"Document" => 200,
|
8
|
+
"Graph" => 1,
|
9
|
+
"Vertex" => 50,
|
10
|
+
"Edge" => 100,
|
11
|
+
"Index" => 20,
|
12
|
+
"AQL" => 100,
|
13
|
+
"User" => 50,
|
14
|
+
"Task" => 20,
|
15
|
+
"Traversal" => 20,
|
16
|
+
"Transaction" => 20,
|
17
|
+
"Other" => 100
|
18
|
+
}
|
19
|
+
@cache = {
|
20
|
+
"Database" => {},
|
21
|
+
"Collection" => {},
|
22
|
+
"Document" => {},
|
23
|
+
"Graph" => {},
|
24
|
+
"Vertex" => {},
|
25
|
+
"Edge" => {},
|
26
|
+
"Index" => {},
|
27
|
+
"AQL" => {},
|
28
|
+
"User" => {},
|
29
|
+
"Task" => {},
|
30
|
+
"Traversal" => {},
|
31
|
+
"Transaction" => {},
|
32
|
+
"Other" => {}
|
33
|
+
}
|
34
|
+
|
35
|
+
class << self
|
36
|
+
attr_accessor :max
|
37
|
+
|
38
|
+
def max(type:, val:)
|
39
|
+
return nil if @max[type].nil?
|
40
|
+
while @cache[type].length > val
|
41
|
+
@cache[type].shift
|
42
|
+
end
|
43
|
+
@max[type] = val
|
44
|
+
end
|
45
|
+
|
46
|
+
def retrieve
|
47
|
+
@cache
|
48
|
+
end
|
49
|
+
|
50
|
+
def cache(id: nil, data:)
|
51
|
+
val_to_cache = []
|
52
|
+
data = [data] unless data.is_a? Array
|
53
|
+
|
54
|
+
if id.nil?
|
55
|
+
data.each do |d|
|
56
|
+
type = d.class.to_s
|
57
|
+
type.slice! "Arango"
|
58
|
+
if @max[type].nil?
|
59
|
+
type = "Other"
|
60
|
+
idCache = "OTH_#{d.class.to_s}_#{Random.rand(10^12)}"
|
61
|
+
else
|
62
|
+
idCache = d.idCache
|
63
|
+
end
|
64
|
+
val_to_cache << [type, idCache, d]
|
65
|
+
end
|
66
|
+
else
|
67
|
+
id = [id] unless id.is_a? Array
|
68
|
+
if data.length == id.length
|
69
|
+
for i in 0...id.length
|
70
|
+
type = data[i].class.to_s
|
71
|
+
type.slice! "Arango"
|
72
|
+
type = "Other" if @max[type].nil?
|
73
|
+
val_to_cache << [type, id[i], data[i]]
|
74
|
+
end
|
75
|
+
else
|
76
|
+
return "Id should be a String or an Array with the same size of the Data Array"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
val_to_cache.each do |val|
|
81
|
+
@cache[val[0]][val[1]] = val[2]
|
82
|
+
@cache[val[0]].shift if @cache[val[0]].length > @max[val[0]]
|
83
|
+
end
|
84
|
+
|
85
|
+
val_to_cache
|
86
|
+
end
|
87
|
+
|
88
|
+
def uncache(type: nil, id: nil, data: nil)
|
89
|
+
if id.nil? && data.nil? && !type.nil?
|
90
|
+
val_to_uncache = @cache[type].map{|k,v| v}
|
91
|
+
val_to_uncache = val_to_uncache[0] if val_to_uncache.length == 1
|
92
|
+
return val_to_uncache
|
93
|
+
end
|
94
|
+
|
95
|
+
val_to_uncache = []
|
96
|
+
unless data.nil?
|
97
|
+
data = [data] unless data.is_a? Array
|
98
|
+
data.each do |d|
|
99
|
+
type = d.class.to_s
|
100
|
+
type.slice! "Arango"
|
101
|
+
next if @max[type].nil? || type == "Other"
|
102
|
+
idCache = d.idCache
|
103
|
+
val_to_uncache << [type, idCache]
|
104
|
+
end
|
105
|
+
end
|
106
|
+
unless type.nil? || id.nil?
|
107
|
+
id = [id] unless id.is_a? Array
|
108
|
+
if type.is_a? Array
|
109
|
+
if type.length == id.length
|
110
|
+
for i in 0...type.length
|
111
|
+
val_to_uncache << [type[i], id[i]]
|
112
|
+
end
|
113
|
+
else
|
114
|
+
return "Type should be a String or an Array with the same size of the Id Array"
|
115
|
+
end
|
116
|
+
elsif type.is_a? String
|
117
|
+
id.each do |idCache|
|
118
|
+
val_to_uncache << [type, idCache]
|
119
|
+
end
|
120
|
+
else
|
121
|
+
return "Type should be a String or an Array with the same size of the Id Array"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
val_to_uncache = val_to_uncache.map{|val| @cache[val[0]][val[1]]}
|
125
|
+
val_to_uncache = val_to_uncache[0] if val_to_uncache.length == 1
|
126
|
+
val_to_uncache
|
127
|
+
end
|
128
|
+
|
129
|
+
def clear(type: nil, id: nil, data: nil)
|
130
|
+
if type.nil? && id.nil? && data.nil?
|
131
|
+
@cache = { "Database" => {}, "Collection" => {}, "Document" => {}, "Graph" => {}, "Vertex" => {}, "Edge" => {}, "Index" => {}, "Query" => {},"User" => {}, "Traversal" => {}, "Transaction" => {} }
|
132
|
+
return true
|
133
|
+
end
|
134
|
+
|
135
|
+
if !type.nil? && id.nil? && data.nil?
|
136
|
+
@cache[type] = {}
|
137
|
+
return true
|
138
|
+
end
|
139
|
+
|
140
|
+
val_to_clear = []
|
141
|
+
unless data.nil?
|
142
|
+
data = [data] unless data.is_a? Array
|
143
|
+
data.each do |d|
|
144
|
+
type = d.class.to_s
|
145
|
+
type.slice! "Arango"
|
146
|
+
next if @max[type].nil? || type == "Other"
|
147
|
+
val_to_clear << [type, d.idCache]
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
unless type.nil? || id.nil?
|
152
|
+
id = [id] unless id.is_a? Array
|
153
|
+
if type.is_a? Array
|
154
|
+
if type.length == id.length
|
155
|
+
for i in 0...type.length
|
156
|
+
val_to_clear << [type[i], id[i]]
|
157
|
+
end
|
158
|
+
else
|
159
|
+
return "Type should be a String or an Array with the same size of the Id Array"
|
160
|
+
end
|
161
|
+
elsif type.is_a? String
|
162
|
+
id.each do |idCache|
|
163
|
+
val_to_clear << [type, idCache]
|
164
|
+
end
|
165
|
+
else
|
166
|
+
return "Type should be a String or an Array with the same size of the Id Array"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
val_to_clear.each{|val| @cache[val[0]].delete(val[1])}
|
171
|
+
true
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|