factbase 0.14.5 → 0.14.7
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 +26 -26
- data/lib/factbase/inv.rb +4 -0
- data/lib/factbase/rules.rb +11 -5
- data/lib/factbase/sync/sync_query.rb +5 -0
- data/lib/factbase/tallied.rb +4 -0
- data/lib/factbase/version.rb +1 -1
- data/test/factbase/test_query.rb +21 -2
- data/test/factbase/test_rules.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64a0e23c152de8f55a3ca0b94a90a123d6d7cea7d1288d41cbb34ac8e11deae4
|
4
|
+
data.tar.gz: 67ce5f29a5a4d1e2fbb7436bade89907ae33d6f80926d32be2d999248fc642bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3605722b88fd2ea98d242e16b6e9760bf24703b12c5169db318f68e80e5f0782b0434f1e8087d6ca751b361b24dc6f768c7b1b4ea6a71d07179d22460d54f325
|
7
|
+
data.tar.gz: 6f01d24ea249d7d951776c785439abba4dfb3ca81efe13c789d8222480b35033428dada4062ed2ffbf452257efb6a9cc1aaff45ce889d63002122fcbfa31a3fa
|
data/README.md
CHANGED
@@ -210,35 +210,35 @@ This is the result of the benchmark:
|
|
210
210
|
<!-- benchmark_begin -->
|
211
211
|
```text
|
212
212
|
user
|
213
|
-
insert 20000 facts 0.
|
214
|
-
export 20000 facts 0.
|
215
|
-
import
|
216
|
-
insert 10 facts 0.
|
217
|
-
query 10 times w/txn 2.
|
218
|
-
query 10 times w/o txn 0.
|
219
|
-
modify 10 attrs w/txn
|
220
|
-
delete 10 facts w/txn 1.
|
221
|
-
(and (eq what 'issue-was-closed') (exists... -> 200 2.
|
222
|
-
(and (eq what 'issue-was-closed') (exists... -> 200/txn 1.
|
223
|
-
(and (eq what 'issue-was-closed') (exists... -> zero 2.
|
224
|
-
(and (eq what 'issue-was-closed') (exists... -> zero/txn 1.
|
225
|
-
(gt time '2024-03-23T03:21:43Z') 0.
|
226
|
-
(gt cost 50) 0.
|
227
|
-
(eq title 'Object Thinking 5000') 0.
|
228
|
-
(and (eq foo 42.998) (or (gt bar 200) (absent z... 0.
|
229
|
-
(and (exists foo) (not (exists blue))) 0.
|
230
|
-
(eq id (agg (always) (max id))) 0.
|
231
|
-
(join "c<=cost,b<=bar" (eq id (agg (always) (ma... 1.
|
232
|
-
(and (eq what "foo") (join "w<=what" (and (eq i... 6.
|
233
|
-
delete! 0.
|
234
|
-
Taped.append() x50000 0.
|
235
|
-
Taped.each() x125 1.
|
236
|
-
Taped.delete_if() x375 0.
|
213
|
+
insert 20000 facts 0.638553
|
214
|
+
export 20000 facts 0.027273
|
215
|
+
import 410717 bytes (20000 facts) 0.021643
|
216
|
+
insert 10 facts 0.042390
|
217
|
+
query 10 times w/txn 2.278994
|
218
|
+
query 10 times w/o txn 0.037285
|
219
|
+
modify 10 attrs w/txn 2.261902
|
220
|
+
delete 10 facts w/txn 1.205367
|
221
|
+
(and (eq what 'issue-was-closed') (exists... -> 200 2.092734
|
222
|
+
(and (eq what 'issue-was-closed') (exists... -> 200/txn 1.032410
|
223
|
+
(and (eq what 'issue-was-closed') (exists... -> zero 2.385969
|
224
|
+
(and (eq what 'issue-was-closed') (exists... -> zero/txn 1.190590
|
225
|
+
(gt time '2024-03-23T03:21:43Z') 0.321057
|
226
|
+
(gt cost 50) 0.210374
|
227
|
+
(eq title 'Object Thinking 5000') 0.055549
|
228
|
+
(and (eq foo 42.998) (or (gt bar 200) (absent z... 0.049508
|
229
|
+
(and (exists foo) (not (exists blue))) 0.999753
|
230
|
+
(eq id (agg (always) (max id))) 0.627528
|
231
|
+
(join "c<=cost,b<=bar" (eq id (agg (always) (ma... 1.246746
|
232
|
+
(and (eq what "foo") (join "w<=what" (and (eq i... 6.881145
|
233
|
+
delete! 0.174194
|
234
|
+
Taped.append() x50000 0.023669
|
235
|
+
Taped.each() x125 1.423781
|
236
|
+
Taped.delete_if() x375 0.843940
|
237
237
|
```
|
238
238
|
|
239
239
|
The results were calculated in [this GHA job][benchmark-gha]
|
240
|
-
on 2025-
|
240
|
+
on 2025-08-09 at 06:42,
|
241
241
|
on Linux with 4 CPUs.
|
242
242
|
<!-- benchmark_end -->
|
243
243
|
|
244
|
-
[benchmark-gha]: https://github.com/yegor256/factbase/actions/runs/
|
244
|
+
[benchmark-gha]: https://github.com/yegor256/factbase/actions/runs/16846550540
|
data/lib/factbase/inv.rb
CHANGED
data/lib/factbase/rules.rb
CHANGED
@@ -40,8 +40,8 @@ class Factbase::Rules
|
|
40
40
|
Fact.new(@fb.insert, @check, @fb)
|
41
41
|
end
|
42
42
|
|
43
|
-
def query(
|
44
|
-
Query.new(@fb.query(
|
43
|
+
def query(term, maps = nil)
|
44
|
+
Query.new(@fb.query(term, maps), @check, self)
|
45
45
|
end
|
46
46
|
|
47
47
|
def txn
|
@@ -78,7 +78,7 @@ class Factbase::Rules
|
|
78
78
|
|
79
79
|
others do |*args|
|
80
80
|
r = @fact.method_missing(*args)
|
81
|
-
k = args
|
81
|
+
k = args.first.to_s
|
82
82
|
@check.it(@fact, @fb) if k.end_with?('=')
|
83
83
|
r
|
84
84
|
end
|
@@ -96,6 +96,10 @@ class Factbase::Rules
|
|
96
96
|
@fb = fb
|
97
97
|
end
|
98
98
|
|
99
|
+
def to_s
|
100
|
+
@query.to_s
|
101
|
+
end
|
102
|
+
|
99
103
|
def each(fb = @fb, params = {})
|
100
104
|
return to_enum(__method__, fb, params) unless block_given?
|
101
105
|
@query.each(fb, params) do |f|
|
@@ -132,14 +136,16 @@ class Factbase::Rules
|
|
132
136
|
return if @uid.nil?
|
133
137
|
a = fact[@uid]
|
134
138
|
return if a.nil?
|
135
|
-
@
|
139
|
+
raise "More than one #{@uid.inspect} in the fact: #{a}" if a.size > 1
|
140
|
+
@facts << a.first
|
136
141
|
end
|
137
142
|
|
138
143
|
def include?(fact)
|
139
144
|
return true if @uid.nil?
|
140
145
|
a = fact[@uid]
|
141
146
|
return true if a.nil?
|
142
|
-
@
|
147
|
+
raise "More than one #{@uid.inspect} in the fact: #{a}" if a.size > 1
|
148
|
+
@facts.include?(a.first)
|
143
149
|
end
|
144
150
|
end
|
145
151
|
end
|
@@ -20,6 +20,11 @@ class Factbase::SyncQuery
|
|
20
20
|
@fb = fb
|
21
21
|
end
|
22
22
|
|
23
|
+
# Turn it to a string.
|
24
|
+
def to_s
|
25
|
+
@origin.to_s
|
26
|
+
end
|
27
|
+
|
23
28
|
# Iterate facts one by one.
|
24
29
|
# @param [Hash] params Optional params accessible in the query via the "$" symbol
|
25
30
|
# @yield [Fact] Facts one-by-one
|
data/lib/factbase/tallied.rb
CHANGED
data/lib/factbase/version.rb
CHANGED
data/test/factbase/test_query.rb
CHANGED
@@ -265,6 +265,12 @@ class TestQuery < Factbase::Test
|
|
265
265
|
end
|
266
266
|
end
|
267
267
|
|
268
|
+
def test_turns_query_to_string
|
269
|
+
with_factbases do |badge, fb|
|
270
|
+
assert_equal('(always)', fb.query('(always)').to_s, "Fails with #{badge}")
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
268
274
|
def test_to_array
|
269
275
|
maps = []
|
270
276
|
maps << { 'foo' => [42] }
|
@@ -336,8 +342,21 @@ class TestQuery < Factbase::Test
|
|
336
342
|
)
|
337
343
|
),
|
338
344
|
'logged+plain' => Factbase::Logged.new(Factbase.new(maps), Loog::NULL),
|
339
|
-
'indexed+cached+plain' => Factbase::IndexedFactbase.new(
|
340
|
-
|
345
|
+
'indexed+cached+plain' => Factbase::IndexedFactbase.new(
|
346
|
+
Factbase::CachedFactbase.new(Factbase.new(maps))
|
347
|
+
),
|
348
|
+
'indexed+cached+rules+plain' => Factbase::IndexedFactbase.new(
|
349
|
+
Factbase::CachedFactbase.new(
|
350
|
+
Factbase::Rules.new(
|
351
|
+
Factbase.new(maps),
|
352
|
+
'(always)',
|
353
|
+
uid: '_id'
|
354
|
+
)
|
355
|
+
)
|
356
|
+
),
|
357
|
+
'cached+indexed+plain' => Factbase::CachedFactbase.new(
|
358
|
+
Factbase::IndexedFactbase.new(Factbase.new(maps))
|
359
|
+
),
|
341
360
|
'indexed+indexed+plain' => Factbase::IndexedFactbase.new(
|
342
361
|
Factbase::IndexedFactbase.new(Factbase.new(maps))
|
343
362
|
),
|
data/test/factbase/test_rules.rb
CHANGED
@@ -80,6 +80,18 @@ class TestRules < Factbase::Test
|
|
80
80
|
assert_equal(0, fb.size)
|
81
81
|
end
|
82
82
|
|
83
|
+
def test_defends_against_id_duplicates
|
84
|
+
fb = Factbase::Rules.new(Factbase.new, '(always)', uid: 'id')
|
85
|
+
assert_raises(StandardError) do
|
86
|
+
fb.txn do |fbt|
|
87
|
+
fbt.insert.then do |f|
|
88
|
+
f.id = 1
|
89
|
+
f.id = 2
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
83
95
|
def test_in_combination_with_pre
|
84
96
|
fb = Factbase::Rules.new(Factbase.new, '(when (exists a) (exists b))')
|
85
97
|
fb =
|