factbase 0.14.5 → 0.14.6
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/rules.rb +7 -5
- data/lib/factbase/version.rb +1 -1
- data/test/factbase/test_query.rb +15 -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: a74a73e5bfec2f7ff39d41428d6c1cbacaaf374d7b2d4b987df0833a0864f0d3
|
4
|
+
data.tar.gz: 684f79dcdae19e8fe5a2b3deb6b21d786e5f9b75e81624a08a5a28f9af3e8597
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29ebcc501c156e5d84d216224918df28df4dfb114e438139b90276a297bdefa373bc848d0d93919035444a40f29c77e83aa22a2e29e5c04e10aa3d5db71068a0
|
7
|
+
data.tar.gz: 8741e804d14332085756fe5c15edb1efa28d0db8357e445f42a097d96d6f63fe87bb48ca2f9b7239e7ed87ca87d7722001be6bf8564824384033b1bb86bb543f
|
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/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
|
@@ -132,14 +132,16 @@ class Factbase::Rules
|
|
132
132
|
return if @uid.nil?
|
133
133
|
a = fact[@uid]
|
134
134
|
return if a.nil?
|
135
|
-
@
|
135
|
+
raise "More than one #{@uid.inspect} in the fact: #{a}" if a.size > 1
|
136
|
+
@facts << a.first
|
136
137
|
end
|
137
138
|
|
138
139
|
def include?(fact)
|
139
140
|
return true if @uid.nil?
|
140
141
|
a = fact[@uid]
|
141
142
|
return true if a.nil?
|
142
|
-
@
|
143
|
+
raise "More than one #{@uid.inspect} in the fact: #{a}" if a.size > 1
|
144
|
+
@facts.include?(a.first)
|
143
145
|
end
|
144
146
|
end
|
145
147
|
end
|
data/lib/factbase/version.rb
CHANGED
data/test/factbase/test_query.rb
CHANGED
@@ -336,8 +336,21 @@ class TestQuery < Factbase::Test
|
|
336
336
|
)
|
337
337
|
),
|
338
338
|
'logged+plain' => Factbase::Logged.new(Factbase.new(maps), Loog::NULL),
|
339
|
-
'indexed+cached+plain' => Factbase::IndexedFactbase.new(
|
340
|
-
|
339
|
+
'indexed+cached+plain' => Factbase::IndexedFactbase.new(
|
340
|
+
Factbase::CachedFactbase.new(Factbase.new(maps))
|
341
|
+
),
|
342
|
+
'indexed+cached+rules+plain' => Factbase::IndexedFactbase.new(
|
343
|
+
Factbase::CachedFactbase.new(
|
344
|
+
Factbase::Rules.new(
|
345
|
+
Factbase.new(maps),
|
346
|
+
'(always)',
|
347
|
+
uid: '_id'
|
348
|
+
)
|
349
|
+
)
|
350
|
+
),
|
351
|
+
'cached+indexed+plain' => Factbase::CachedFactbase.new(
|
352
|
+
Factbase::IndexedFactbase.new(Factbase.new(maps))
|
353
|
+
),
|
341
354
|
'indexed+indexed+plain' => Factbase::IndexedFactbase.new(
|
342
355
|
Factbase::IndexedFactbase.new(Factbase.new(maps))
|
343
356
|
),
|
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 =
|