factbase 0.14.1 → 0.14.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a637de7c717d650eb0c6721794afd2c4a3bbb31a3eda1b1150f8a2f3e1c5322
|
4
|
+
data.tar.gz: a0a7698bba101d67c20fd390f1e745679110687643ec6849c445898b26a0d04e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99cbde1626587ef0d3552258089dcf9a25f956ee83766f4273d8928faa769995e7150925d0ae2d9506366eed80a4347d3302c7e0f00e854ff1671e6294e78452
|
7
|
+
data.tar.gz: 7aa47a8c5fd5dd2ff8a7e63fe7f203f9889a26bd7f20c94b3b126fe9cf8d52c78a5f5131d684e232b3ac37961c7c074f02531afe53c41e2904509b211441cf15
|
data/lib/factbase/impatient.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
6
|
require 'decoor'
|
7
|
+
require 'tago'
|
7
8
|
require 'timeout'
|
8
9
|
require_relative 'syntax'
|
9
10
|
|
@@ -61,7 +62,7 @@ class Factbase::Impatient
|
|
61
62
|
qry.each(fb, params, &)
|
62
63
|
end
|
63
64
|
rescue Timeout::Error => e
|
64
|
-
raise "
|
65
|
+
raise "each() timed out after #{@timeout.seconds} (#{e.message}): #{@term}"
|
65
66
|
end
|
66
67
|
|
67
68
|
def one(fb = @fb, params = {})
|
@@ -70,7 +71,7 @@ class Factbase::Impatient
|
|
70
71
|
qry.one(fb, params)
|
71
72
|
end
|
72
73
|
rescue Timeout::Error => e
|
73
|
-
raise "
|
74
|
+
raise "one() timed out after #{@timeout.seconds} (#{e.message}): #{@term}"
|
74
75
|
end
|
75
76
|
|
76
77
|
def delete!(fb = @fb)
|
@@ -79,7 +80,7 @@ class Factbase::Impatient
|
|
79
80
|
qry.delete!(fb)
|
80
81
|
end
|
81
82
|
rescue Timeout::Error => e
|
82
|
-
raise "
|
83
|
+
raise "delete!() timed out after #{@timeout.seconds} (#{e.message}): #{@term}"
|
83
84
|
end
|
84
85
|
end
|
85
86
|
end
|
@@ -40,6 +40,15 @@ module Factbase::IndexedTerm
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
(maps & []) | @idx[key]
|
43
|
+
when :absent
|
44
|
+
if @idx[key].nil?
|
45
|
+
@idx[key] = []
|
46
|
+
prop = @operands.first.to_s
|
47
|
+
maps.to_a.each do |m|
|
48
|
+
@idx[key].append(m) if m[prop].nil?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
(maps & []) | @idx[key]
|
43
52
|
when :eq
|
44
53
|
if @operands.first.is_a?(Symbol) && _scalar?(@operands[1])
|
45
54
|
if @idx[key].nil?
|
@@ -59,7 +68,7 @@ module Factbase::IndexedTerm
|
|
59
68
|
[@operands[1]]
|
60
69
|
end
|
61
70
|
if vv.empty?
|
62
|
-
|
71
|
+
(maps & [])
|
63
72
|
else
|
64
73
|
j = vv.map { |v| @idx[key][v] || [] }.reduce(&:|)
|
65
74
|
(maps & []) | j
|
data/lib/factbase/version.rb
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
4
|
# SPDX-License-Identifier: MIT
|
5
5
|
|
6
|
+
require 'elapsed'
|
7
|
+
require 'loog'
|
8
|
+
require 'timeout'
|
6
9
|
require_relative '../../test__helper'
|
7
10
|
require_relative '../../../lib/factbase'
|
8
11
|
require_relative '../../../lib/factbase/indexed/indexed_factbase'
|
@@ -58,4 +61,36 @@ class TestIndexedFactbase < Factbase::Test
|
|
58
61
|
fb.txn(&:insert)
|
59
62
|
refute_empty(fb.query('(always)').each.to_a)
|
60
63
|
end
|
64
|
+
|
65
|
+
def test_works_with_huge_dataset
|
66
|
+
fb = Factbase.new
|
67
|
+
fb = Factbase::IndexedFactbase.new(fb)
|
68
|
+
10_000.times do |i|
|
69
|
+
fb.insert.then do |f|
|
70
|
+
f.id = i
|
71
|
+
f.foo = [42, 1, 256, 7, 99].sample
|
72
|
+
f.bar = [42, 13, 88, 19, 93].sample
|
73
|
+
f.rarely = rand if rand > 0.95
|
74
|
+
f.often = rand if rand > 0.05
|
75
|
+
end
|
76
|
+
end
|
77
|
+
[
|
78
|
+
'(and (eq foo 42) (exists bar))',
|
79
|
+
'(and (eq foo 42) (exists rarely))',
|
80
|
+
'(and (eq foo 42) (exists often))',
|
81
|
+
'(and (eq foo 42) (exists often) (exists bar) (absent rarely))',
|
82
|
+
'(and (eq foo 42) (empty (eq foo 888)))',
|
83
|
+
'(and (eq foo 42) (empty (eq foo $id)))',
|
84
|
+
'(and (eq foo 42) (empty (eq foo $often)))',
|
85
|
+
'(and (eq foo 42) (empty (and (eq foo $often) (gt foo 43))))',
|
86
|
+
'(and (eq foo 42) (empty (and (eq foo 42) (eq bar 42) (eq id -1))))',
|
87
|
+
'(and (eq foo 42) (empty (exists another)))'
|
88
|
+
].each do |q|
|
89
|
+
Timeout.timeout(4) do
|
90
|
+
elapsed(Loog::NULL, good: q) do
|
91
|
+
refute_empty(fb.query(q).each.to_a)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
61
96
|
end
|
@@ -92,7 +92,7 @@ class TestImpatient < Factbase::Test
|
|
92
92
|
sleep 0.2
|
93
93
|
end
|
94
94
|
end
|
95
|
-
assert_includes(ex.message, '
|
95
|
+
assert_includes(ex.message, 'timed out after')
|
96
96
|
end
|
97
97
|
|
98
98
|
def test_query_one_timeout
|
@@ -105,7 +105,7 @@ class TestImpatient < Factbase::Test
|
|
105
105
|
assert_raises(StandardError) do
|
106
106
|
fb.query('(agg (min value))').one
|
107
107
|
end
|
108
|
-
assert_includes(ex.message, '
|
108
|
+
assert_includes(ex.message, 'timed out after')
|
109
109
|
end
|
110
110
|
|
111
111
|
def test_delete_timeout
|
@@ -118,7 +118,7 @@ class TestImpatient < Factbase::Test
|
|
118
118
|
assert_raises(StandardError) do
|
119
119
|
fb.query('(gt value 500)').delete!
|
120
120
|
end
|
121
|
-
assert_includes(ex.message, '
|
121
|
+
assert_includes(ex.message, 'timed out after')
|
122
122
|
end
|
123
123
|
|
124
124
|
def test_with_txn
|
@@ -141,7 +141,7 @@ class TestImpatient < Factbase::Test
|
|
141
141
|
sleep 0.2
|
142
142
|
end
|
143
143
|
end
|
144
|
-
assert_includes(ex.message, '
|
144
|
+
assert_includes(ex.message, 'timed out after')
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|