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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fdee6a1a98e26f25786c6f9bffbaf201d39639b52bf8933beaa4a8053860dfde
4
- data.tar.gz: ca5ccea23c49c9ffc45d4cebf77b798bb42a527d599533d854836bf47276a532
3
+ metadata.gz: 64a0e23c152de8f55a3ca0b94a90a123d6d7cea7d1288d41cbb34ac8e11deae4
4
+ data.tar.gz: 67ce5f29a5a4d1e2fbb7436bade89907ae33d6f80926d32be2d999248fc642bb
5
5
  SHA512:
6
- metadata.gz: 37a08deb9fba4cc348861fe67dd680328b635f10366f193baf9e4f955118e60a1439562416d2e7bd5e5e140243250a6daec6ce72049ad40132b987c55c16ff88
7
- data.tar.gz: c4dd0a22cfa88b3c2b4d5c87c672fe0cbbd81959dc0c96e6d8e3b4bdacec3c5ef3448b5832b9b91378d4fe4629cae72ec6af71de05ad029052478068fe6626cd
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.658630
214
- export 20000 facts 0.025967
215
- import 411020 bytes (20000 facts) 0.024282
216
- insert 10 facts 0.050191
217
- query 10 times w/txn 2.063964
218
- query 10 times w/o txn 0.044326
219
- modify 10 attrs w/txn 1.745367
220
- delete 10 facts w/txn 1.023205
221
- (and (eq what 'issue-was-closed') (exists... -> 200 2.043080
222
- (and (eq what 'issue-was-closed') (exists... -> 200/txn 1.019861
223
- (and (eq what 'issue-was-closed') (exists... -> zero 2.350912
224
- (and (eq what 'issue-was-closed') (exists... -> zero/txn 1.187649
225
- (gt time '2024-03-23T03:21:43Z') 0.304861
226
- (gt cost 50) 0.234136
227
- (eq title 'Object Thinking 5000') 0.091766
228
- (and (eq foo 42.998) (or (gt bar 200) (absent z... 0.049974
229
- (and (exists foo) (not (exists blue))) 0.926298
230
- (eq id (agg (always) (max id))) 0.606111
231
- (join "c<=cost,b<=bar" (eq id (agg (always) (ma... 1.276007
232
- (and (eq what "foo") (join "w<=what" (and (eq i... 6.827440
233
- delete! 0.218373
234
- Taped.append() x50000 0.023564
235
- Taped.each() x125 1.348705
236
- Taped.delete_if() x375 0.812740
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-07-28 at 17:02,
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/16575338618
244
+ [benchmark-gha]: https://github.com/yegor256/factbase/actions/runs/16846550540
data/lib/factbase/inv.rb CHANGED
@@ -82,6 +82,10 @@ class Factbase::Inv
82
82
  @fb = fb
83
83
  end
84
84
 
85
+ def to_s
86
+ @query.to_s
87
+ end
88
+
85
89
  def each(fb = @fb, params = {})
86
90
  return to_enum(__method__, fb, params) unless block_given?
87
91
  @query.each(fb, params) do |f|
@@ -40,8 +40,8 @@ class Factbase::Rules
40
40
  Fact.new(@fb.insert, @check, @fb)
41
41
  end
42
42
 
43
- def query(query, maps = nil)
44
- Query.new(@fb.query(query, maps), @check, self)
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[0].to_s
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
- @facts << a[0]
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
- @facts.include?(a[0])
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
@@ -75,6 +75,10 @@ class Factbase::Tallied
75
75
  @fb = fb
76
76
  end
77
77
 
78
+ def to_s
79
+ @query.to_s
80
+ end
81
+
78
82
  def one(fb = @fb, params = {})
79
83
  @query.one(fb, params)
80
84
  end
@@ -9,5 +9,5 @@
9
9
  # License:: MIT
10
10
  class Factbase
11
11
  # Current version of the gem (changed by .rultor.yml on every release)
12
- VERSION = '0.14.5' unless const_defined?(:VERSION)
12
+ VERSION = '0.14.7' unless const_defined?(:VERSION)
13
13
  end
@@ -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(Factbase::CachedFactbase.new(Factbase.new(maps))),
340
- 'cached+indexed+plain' => Factbase::CachedFactbase.new(Factbase::IndexedFactbase.new(Factbase.new(maps))),
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
  ),
@@ -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 =
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.5
4
+ version: 0.14.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko