factbase 0.7.5 → 0.8.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/README.md +24 -27
- data/lib/factbase/logged.rb +23 -11
- data/lib/factbase/syntax.rb +4 -1
- data/lib/factbase.rb +1 -1
- data/test/factbase/test_syntax.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c894341c112c152f36eec0eca4ac83075c2c03fc3978ee8e67f3557c36890511
|
4
|
+
data.tar.gz: 1977919180975069d04b88b1b2e91a088e5ea004c7916de5682a97c627bedee3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13a9aabb04e8edaa4e88435ef78b9ddc4fd9aa7ba53043e808ce315891b723f2014f964a02e9cb01e01ec11f60d5a3804e10565d4aab777019b9f32f67d7fe8c
|
7
|
+
data.tar.gz: 000fe549d4bb63c3bfff32533c0bca8baf4738e497f5d12481d63ba7a2d996a981ac2d63c28d8d829187bf27897f21492da64fe26d8bd4b328aec93a8a815141
|
data/README.md
CHANGED
@@ -208,37 +208,34 @@ This is the result of the benchmark:
|
|
208
208
|
|
209
209
|
<!-- benchmark_begin -->
|
210
210
|
```text
|
211
|
-
|
212
|
-
|
213
|
-
Benchmarking, please wait a few seconds...
|
214
211
|
user system total real
|
215
|
-
insert 500 facts 0.
|
216
|
-
export 500 facts 0.
|
217
|
-
import
|
218
|
-
insert 10 facts 0.
|
219
|
-
query 10 times w/txn 0.
|
220
|
-
query 10 times w/o txn 0.
|
221
|
-
modify 10 attrs w/txn 0.
|
222
|
-
delete 10 facts w/txn 0.
|
223
|
-
(and (eq what 'issue-was-closed') (exists... -> 200 7.
|
224
|
-
(and (eq what 'issue-was-closed') (exists... -> 200/txn 8.
|
225
|
-
(and (eq what 'issue-was-closed') (exists... -> zero
|
226
|
-
(and (eq what 'issue-was-closed') (exists... -> zero/txn
|
227
|
-
(gt time '2024-03-23T03:21:43Z') 0.
|
228
|
-
(gt cost 50) 0.
|
229
|
-
(eq title 'Object Thinking 5000') 0.
|
230
|
-
(and (eq foo 42.998) (or (gt bar 200) (absent zzz))) 0.
|
231
|
-
(eq id (agg (always) (max id))) 0.
|
232
|
-
(join "c<=cost,b<=bar" (eq id (agg (always) (max id)))) 0.
|
233
|
-
delete! 0.
|
234
|
-
Taped.append() x50000 0.
|
235
|
-
Taped.each() x125 1.
|
236
|
-
Taped.delete_if() x375 0.
|
212
|
+
insert 500 facts 0.013931 0.001982 0.015913 ( 0.016066)
|
213
|
+
export 500 facts 0.000407 0.000094 0.000501 ( 0.000501)
|
214
|
+
import 10488 bytes (500 facts) 0.000395 0.000000 0.000395 ( 0.000395)
|
215
|
+
insert 10 facts 0.001647 0.000009 0.001656 ( 0.001658)
|
216
|
+
query 10 times w/txn 0.040065 0.002998 0.043063 ( 0.043072)
|
217
|
+
query 10 times w/o txn 0.033030 0.001994 0.035024 ( 0.035026)
|
218
|
+
modify 10 attrs w/txn 0.029632 0.000922 0.030554 ( 0.030556)
|
219
|
+
delete 10 facts w/txn 0.012058 0.000007 0.012065 ( 0.012067)
|
220
|
+
(and (eq what 'issue-was-closed') (exists... -> 200 7.388818 0.008930 7.397748 ( 7.398362)
|
221
|
+
(and (eq what 'issue-was-closed') (exists... -> 200/txn 8.131628 0.015996 8.147624 ( 8.148167)
|
222
|
+
(and (eq what 'issue-was-closed') (exists... -> zero 9.203546 0.013996 9.217542 ( 9.217912)
|
223
|
+
(and (eq what 'issue-was-closed') (exists... -> zero/txn 9.851325 0.014002 9.865327 ( 9.866013)
|
224
|
+
(gt time '2024-03-23T03:21:43Z') 0.008457 0.000000 0.008457 ( 0.008457)
|
225
|
+
(gt cost 50) 0.008325 0.000000 0.008325 ( 0.008326)
|
226
|
+
(eq title 'Object Thinking 5000') 0.008030 0.000000 0.008030 ( 0.008031)
|
227
|
+
(and (eq foo 42.998) (or (gt bar 200) (absent zzz))) 0.011693 0.000000 0.011693 ( 0.011695)
|
228
|
+
(eq id (agg (always) (max id))) 0.019256 0.000000 0.019256 ( 0.019257)
|
229
|
+
(join "c<=cost,b<=bar" (eq id (agg (always) (max id)))) 0.126297 0.000001 0.126298 ( 0.126300)
|
230
|
+
delete! 0.003729 0.000000 0.003729 ( 0.003730)
|
231
|
+
Taped.append() x50000 0.026741 0.006998 0.033739 ( 0.033748)
|
232
|
+
Taped.each() x125 1.413173 0.004001 1.417174 ( 1.417232)
|
233
|
+
Taped.delete_if() x375 0.810399 0.000000 0.810399 ( 0.810419)
|
237
234
|
```
|
238
235
|
|
239
236
|
The results were calculated in [this GHA job][benchmark-gha]
|
240
|
-
on 2025-03-03 at 15:
|
237
|
+
on 2025-03-03 at 15:25,
|
241
238
|
on Linux with 4 CPUs.
|
242
239
|
<!-- benchmark_end -->
|
243
240
|
|
244
|
-
[benchmark-gha]: https://github.com/yegor256/factbase/actions/runs/
|
241
|
+
[benchmark-gha]: https://github.com/yegor256/factbase/actions/runs/13634327165
|
data/lib/factbase/logged.rb
CHANGED
@@ -48,9 +48,9 @@ class Factbase::Logged
|
|
48
48
|
raise e
|
49
49
|
end
|
50
50
|
if rollback
|
51
|
-
@loog
|
51
|
+
Factbase::Logged.log_it(@loog, start, "Txn ##{id} rolled back in #{start.ago}")
|
52
52
|
else
|
53
|
-
@loog
|
53
|
+
Factbase::Logged.log_it(@loog, start, "Txn ##{id} touched #{r} in #{start.ago}")
|
54
54
|
end
|
55
55
|
r
|
56
56
|
end
|
@@ -99,6 +99,7 @@ class Factbase::Logged
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def one(params = {})
|
102
|
+
start = Time.now
|
102
103
|
q = Factbase::Syntax.new(@fb, @expr).to_term.to_s
|
103
104
|
r = nil
|
104
105
|
tail =
|
@@ -106,14 +107,15 @@ class Factbase::Logged
|
|
106
107
|
r = @fb.query(@expr).one(params)
|
107
108
|
end
|
108
109
|
if r.nil?
|
109
|
-
@loog
|
110
|
+
Factbase::Logged.log_it(@loog, start, "Nothing found by '#{q}' #{tail}")
|
110
111
|
else
|
111
|
-
@loog
|
112
|
+
Factbase::Logged.log_it(@loog, start, "Found #{r} (#{r.class}) by '#{q}' #{tail}")
|
112
113
|
end
|
113
114
|
r
|
114
115
|
end
|
115
116
|
|
116
117
|
def each(params = {}, &)
|
118
|
+
start = Time.now
|
117
119
|
q = Factbase::Syntax.new(@fb, @expr).to_term.to_s
|
118
120
|
if block_given?
|
119
121
|
r = nil
|
@@ -123,9 +125,9 @@ class Factbase::Logged
|
|
123
125
|
end
|
124
126
|
raise ".each of #{@expr.class} returned #{r.class}" unless r.is_a?(Integer)
|
125
127
|
if r.zero?
|
126
|
-
@loog
|
128
|
+
Factbase::Logged.log_it(@loog, start, "Nothing found by '#{q}' #{tail}")
|
127
129
|
else
|
128
|
-
@loog
|
130
|
+
Factbase::Logged.log_it(@loog, start, "Found #{r} fact(s) by '#{q}' #{tail}")
|
129
131
|
end
|
130
132
|
r
|
131
133
|
else
|
@@ -137,9 +139,9 @@ class Factbase::Logged
|
|
137
139
|
end
|
138
140
|
end
|
139
141
|
if array.empty?
|
140
|
-
@loog
|
142
|
+
Factbase::Logged.log_it(@loog, start, "Nothing found by '#{q}' #{tail}")
|
141
143
|
else
|
142
|
-
@loog
|
144
|
+
Factbase::Logged.log_it(@loog, start, "Found #{array.size} fact(s) by '#{q}' #{tail}")
|
143
145
|
end
|
144
146
|
array
|
145
147
|
end
|
@@ -147,6 +149,7 @@ class Factbase::Logged
|
|
147
149
|
|
148
150
|
def delete!
|
149
151
|
r = nil
|
152
|
+
start = Time.now
|
150
153
|
before = @fb.size
|
151
154
|
tail =
|
152
155
|
Factbase::Logged.elapsed do
|
@@ -154,11 +157,11 @@ class Factbase::Logged
|
|
154
157
|
end
|
155
158
|
raise ".delete! of #{@expr.class} returned #{r.class}" unless r.is_a?(Integer)
|
156
159
|
if before.zero?
|
157
|
-
@loog
|
160
|
+
Factbase::Logged.log_it(@loog, start, "There were no facts, nothing deleted by '#{@expr}' #{tail}")
|
158
161
|
elsif r.zero?
|
159
|
-
@loog
|
162
|
+
Factbase::Logged.log_it(@loog, start, "No facts out of #{before} deleted by '#{@expr}' #{tail}")
|
160
163
|
else
|
161
|
-
@loog
|
164
|
+
Factbase::Logged.log_it(@loog, start, "Deleted #{r} fact(s) out of #{before} by '#{@expr}' #{tail}")
|
162
165
|
end
|
163
166
|
r
|
164
167
|
end
|
@@ -169,4 +172,13 @@ class Factbase::Logged
|
|
169
172
|
yield
|
170
173
|
"in #{start.ago}"
|
171
174
|
end
|
175
|
+
|
176
|
+
def self.log_it(loog, start, msg)
|
177
|
+
m = :debug
|
178
|
+
if Time.now - start > 1
|
179
|
+
msg = "#{msg} (slow!)"
|
180
|
+
m = :warn
|
181
|
+
end
|
182
|
+
loog.send(m, msg)
|
183
|
+
end
|
172
184
|
end
|
data/lib/factbase/syntax.rb
CHANGED
@@ -28,6 +28,9 @@ require_relative 'term_once'
|
|
28
28
|
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
29
29
|
# License:: MIT
|
30
30
|
class Factbase::Syntax
|
31
|
+
# If the syntax is broken.
|
32
|
+
class Broken < StandardError; end
|
33
|
+
|
31
34
|
# Ctor.
|
32
35
|
#
|
33
36
|
# The class provided as the +term+ argument must have a three-argument
|
@@ -57,7 +60,7 @@ class Factbase::Syntax
|
|
57
60
|
rescue StandardError => e
|
58
61
|
err = "#{e.message} (#{Backtrace.new(e)}) in \"#{@query}\""
|
59
62
|
err = "#{err}, tokens: #{@tokens}" unless @tokens.nil?
|
60
|
-
raise err
|
63
|
+
raise Broken, err
|
61
64
|
end
|
62
65
|
|
63
66
|
private
|
data/lib/factbase.rb
CHANGED
@@ -64,7 +64,7 @@ require 'yaml'
|
|
64
64
|
# License:: MIT
|
65
65
|
class Factbase
|
66
66
|
# Current version of the gem (changed by .rultor.yml on every release)
|
67
|
-
VERSION = '0.
|
67
|
+
VERSION = '0.8.0'
|
68
68
|
|
69
69
|
# An exception that may be thrown in a transaction, to roll it back.
|
70
70
|
class Rollback < StandardError; end
|
@@ -119,6 +119,19 @@ class TestSyntax < Factbase::Test
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
+
def test_raises_on_broken_syntax
|
123
|
+
100.times do
|
124
|
+
q = [
|
125
|
+
'(', ')', '#test', '$foo', '%what',
|
126
|
+
'"hello"', '42', '+', '?', '!', '\"',
|
127
|
+
'\'', 'привет'
|
128
|
+
].shuffle.join(' . ')
|
129
|
+
assert_raises(Factbase::Syntax::Broken, q) do
|
130
|
+
Factbase::Syntax.new(Factbase.new, q).to_term
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
122
135
|
def test_simplification
|
123
136
|
{
|
124
137
|
'(foo)' => '(foo)',
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factbase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-04 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: backtrace
|