factbase 0.19.0 → 0.19.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: c20d4add4664149fc5c070ec64321a79c8ac07ef81c69ae2b64bac1e9fd0c4e9
4
- data.tar.gz: ff9a8f121d9cfafa6ad97a634c79fc2ec834a07ee0d17042eb3fc5fa8c529501
3
+ metadata.gz: 515345c86598dcc29f0795b9bb64fe31fc770469f596185103bc3ae62b95bec9
4
+ data.tar.gz: adcf851edc23a66a4297bf4888ae54987431cc853f3157d751bbb57f5a89ef01
5
5
  SHA512:
6
- metadata.gz: 3f93283308d6f15766fca09f253da85145efc28975e51259ee88f0954cc6a7f584700de2ff604478bd5a48f1c86153243949a6280732a466412a739f38e9a1e2
7
- data.tar.gz: e21602f7612821dd2389e831056389900f62a3ef3b1bf998f6ebbe722cfc9684357383c754ad0556a346534cf7a6bc76489706e0f0f58ea23336a918be71b442
6
+ metadata.gz: 37488e2dd8a395abb1ddfb4700fa794592d3ce910981f4c468c2f6b0ebdfa703400873f5caea6cdee42a62971ae88009956fb6cb38b3bc5d8eebca698bdf4367
7
+ data.tar.gz: 7798feb2f2e05fb795e6cfffe3a3311d6e2867fd4b21d1ffb5f1e03aa818bacae442faf47a507a99a402081d5048146be883685adcef62a9ace4ef85ac4ee90e
data/Gemfile.lock CHANGED
@@ -36,7 +36,7 @@ GEM
36
36
  logger (1.7.0)
37
37
  loog (0.6.1)
38
38
  logger (~> 1.0)
39
- minitest (5.26.2)
39
+ minitest (5.27.0)
40
40
  minitest-reporters (1.7.1)
41
41
  ansi
42
42
  builder
@@ -31,6 +31,7 @@ class Factbase::CachedFactbase
31
31
  # Insert a new fact and return it.
32
32
  # @return [Factbase::Fact] The fact just inserted
33
33
  def insert
34
+ @cache[:__dirty__] = true
34
35
  Factbase::CachedFact.new(@origin.insert, @cache, fresh: true)
35
36
  end
36
37
 
@@ -35,6 +35,7 @@ class Factbase::CachedQuery
35
35
  # @return [Integer] Total number of facts yielded
36
36
  def each(fb = @fb, params = {})
37
37
  return to_enum(__method__, fb, params) unless block_given?
38
+ invalidate_if_dirty!
38
39
  key = "each #{@origin}" # params are ignored!
39
40
  before = @cache[key]
40
41
  @cache[key] = @origin.each(fb, params).to_a if before.nil?
@@ -51,6 +52,7 @@ class Factbase::CachedQuery
51
52
  # @param [Hash] params Optional params accessible in the query via the "$" symbol (unused)
52
53
  # @return The value evaluated
53
54
  def one(fb = @fb, params = {})
55
+ invalidate_if_dirty!
54
56
  key = "one: #{@origin} #{params}"
55
57
  before = @cache[key]
56
58
  @cache[key] = @origin.one(fb, params) if before.nil?
@@ -63,4 +65,14 @@ class Factbase::CachedQuery
63
65
  @cache.clear
64
66
  @origin.delete!(fb)
65
67
  end
68
+
69
+ private
70
+
71
+ # Clear cache if it was marked dirty by a fresh fact insertion.
72
+ # This implements lazy invalidation: we don't clear on every insert,
73
+ # only when a query actually runs after inserts happened.
74
+ def invalidate_if_dirty!
75
+ return unless @cache.delete(:__dirty__)
76
+ @cache.clear
77
+ end
66
78
  end
@@ -42,8 +42,13 @@ class Factbase::IndexedAnd
42
42
  end
43
43
  end
44
44
  )
45
- j = tuples.map { |t| entry[:index][t] || [] }.reduce(&:|)
46
- r = (maps & []) | j
45
+ j = tuples.flat_map { |t| entry[:index][t] || [] }.uniq(&:object_id)
46
+ r =
47
+ if maps.respond_to?(:inserted)
48
+ Factbase::Taped.new(j, inserted: maps.inserted, deleted: maps.deleted, added: maps.added)
49
+ else
50
+ j
51
+ end
47
52
  else
48
53
  @term.operands.each do |o|
49
54
  n = o.predict(maps, fb, params)
@@ -36,11 +36,11 @@ class Factbase::IndexedEq
36
36
  else
37
37
  [@term.operands[1]]
38
38
  end
39
- if vv.empty?
40
- (maps & [])
39
+ j = vv.flat_map { |v| entry[:index][v] || [] }.uniq(&:object_id)
40
+ if maps.respond_to?(:inserted)
41
+ Factbase::Taped.new(j, inserted: maps.inserted, deleted: maps.deleted, added: maps.added)
41
42
  else
42
- j = vv.map { |v| entry[:index][v] || [] }.reduce(&:|)
43
- (maps & []) | j
43
+ j
44
44
  end
45
45
  end
46
46
 
@@ -49,8 +49,7 @@ class Factbase::IndexedFactbase
49
49
  def query(term, maps = nil)
50
50
  term = to_term(term) if term.is_a?(String)
51
51
  q = @origin.query(term, maps)
52
- q = Factbase::IndexedQuery.new(q, @idx, self) if term.abstract?
53
- q
52
+ Factbase::IndexedQuery.new(q, @idx, self)
54
53
  end
55
54
 
56
55
  # Run an ACID transaction.
@@ -46,7 +46,7 @@ class Factbase::IndexedQuery
46
46
  # @param [Factbase] fb The factbase
47
47
  # @param [Hash] params Optional params accessible in the query via the "$" symbol
48
48
  # @return [String|Integer|Float|Time|Array|NilClass] The value evaluated
49
- def one(fb = @fb, params = nil)
49
+ def one(fb = @fb, params = {})
50
50
  @origin.one(fb, params)
51
51
  end
52
52
 
@@ -54,7 +54,8 @@ class Factbase::IndexedQuery
54
54
  # @param [Factbase] fb The factbase
55
55
  # @return [Integer] Total number of facts deleted
56
56
  def delete!(fb = @fb)
57
+ result = @origin.delete!(fb)
57
58
  @idx.clear
58
- @origin.delete!(fb)
59
+ result
59
60
  end
60
61
  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.19.0' unless const_defined?(:VERSION)
12
+ VERSION = '0.19.2' unless const_defined?(:VERSION)
13
13
  end
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.19.0
4
+ version: 0.19.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko