card-mod-counts 0.1 → 0.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: 07bf8f2a2e551a3ba76bb0a9be5acc9f60d06eafe89acdf74756e3fb69a49280
4
- data.tar.gz: 8a033c80c7e6b778bd34f9c4be1402b73d7fb69daf5a9f16287fac5c88ca1b34
3
+ metadata.gz: a140a2c877d847b1db64601670fceed0c71f192f254209c666b45385bd60702f
4
+ data.tar.gz: 3dac501b4bec70164cf19b5f23e9f38c0f3b470f56b541b0dcb46e7358a1ea1b
5
5
  SHA512:
6
- metadata.gz: 39ed100f2208371f60233693c7b04d6d0e42f8519bbf58259ac83f54e3944e331c487a0313178a3fe3422714f5174bf87bb08f2348351292ba63a6b6d2fb11c0
7
- data.tar.gz: '08f255b8eb96a16f2a4ee5e023fab2d54bb3562dc7f39f8095f4c08ad55a62b271ee274594f420249ecdcfab2c7d5bcda4831df53e5847d93ae9207cb560cdf1'
6
+ metadata.gz: 992719450d8a926a71793e064603fca794be95b2844ba99c0b8a6c649f5575180d25ffe7125b384e79d41e74b6ef81da9cfd5e5474d1f862cdf5d8e279349a19
7
+ data.tar.gz: 81a9b8edc4bbd66da11673ad7f789ea9533c35b1151b924438c1a2dd08432fb4582ed53e02aa75d4d0c112d03745387c8750340b7628c6cbeb25519555f57b57
@@ -10,10 +10,6 @@ def cached_count
10
10
  @cached_count || hard_cached_count(::Count.fetch_value(self))
11
11
  end
12
12
 
13
- def update_cached_count _changed_card=nil
14
- hard_cached_count ::Count.refresh(self)
15
- end
16
-
17
13
  def hard_cached_count value
18
14
  Card.cache.hard&.write_attribute key, :cached_count, value
19
15
  @cached_count = value
@@ -27,6 +23,15 @@ def recount
27
23
  count
28
24
  end
29
25
 
26
+ event :update_cached_count, :integrate_with_delay, trigger: :required do
27
+ hard_cached_count ::Count.refresh(self)
28
+ end
29
+
30
+ # cannot delay event without id
31
+ def update_cached_count_when_ready
32
+ send "update_cached_count#{'_without_callbacks' if new?}"
33
+ end
34
+
30
35
  module ClassMethods
31
36
  # @param parts [Array] set parts of changed card
32
37
  def recount_trigger *set_parts, &block
@@ -36,6 +41,8 @@ module ClassMethods
36
41
  define_recount_event set, event_name, event_args, &block
37
42
  end
38
43
 
44
+ # use in cases where both the base card and the field card can trigger counting
45
+ # (prevents double work)
39
46
  def field_recount field_card
40
47
  yield unless field_card.left&.action&.in? %i[create delete]
41
48
  end
@@ -45,9 +52,7 @@ module ClassMethods
45
52
  def define_recount_event set, event_name, event_args
46
53
  set.class_eval do
47
54
  event event_name, :after_integrate, event_args do
48
- Array.wrap(yield(self)).compact.each do |count_card|
49
- count_card.update_cached_count self if count_card.respond_to? :recount
50
- end
55
+ Array.wrap(yield(self)).compact.each(&:update_cached_count_when_ready)
51
56
  end
52
57
  end
53
58
  end
@@ -17,9 +17,10 @@ def self.included host_class
17
17
  recount_trigger :type_plus_right,
18
18
  host_class.type_to_count,
19
19
  host_class.list_field do |changed_card|
20
- trait_name = host_class.try(:count_trait) || host_class.type_to_count
20
+ field_code = host_class.try(:count_field) || host_class.type_to_count
21
+
21
22
  changed_card.changed_item_names.map do |item_name|
22
- Card.fetch item_name.to_name.trait(trait_name)
23
+ Card.fetch item_name.to_name.field(field_code)
23
24
  end
24
25
  end
25
26
 
@@ -0,0 +1,22 @@
1
+ # Abstract::ListRefCachedCount needs to know which items have been changed.
2
+ # But the standard ActiveModel dirty/mutations mechanism for this is not serializable
3
+ # and therefore cannot be thus preserved for delayed jobs (when the cached counting
4
+ # now takes place.)
5
+ #
6
+ # In the long term it would be preferable to have a more general solution, but for
7
+ # now we are just stashing
8
+
9
+ # Card.action_specific_attributes << :changed_item_names
10
+ #
11
+ # # make these available in delayed jobs
12
+ # event :stash_changed_item_names, :after_integrate do
13
+ # @changed_item_names = changed_item_names.map(&:to_s)
14
+ # end
15
+ #
16
+ # def changed_item_names
17
+ # if @changed_item_names
18
+ # @changed_item_names.map(&:to_name)
19
+ # else
20
+ # dropped_item_names + added_item_names
21
+ # end
22
+ # end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: card-mod-counts
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philipp Kühl
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-10-26 00:00:00.000000000 Z
12
+ date: 2021-12-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: card
@@ -55,6 +55,7 @@ files:
55
55
  - set/abstract/02_search_cached_count.rb
56
56
  - set/abstract/list_cached_count.rb
57
57
  - set/abstract/list_ref_cached_count.rb
58
+ - set/abstract/pointer/events.rb
58
59
  homepage: http://decko.org
59
60
  licenses:
60
61
  - GPL-3.0
@@ -75,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
76
  - !ruby/object:Gem::Version
76
77
  version: '0'
77
78
  requirements: []
78
- rubygems_version: 3.2.28
79
+ rubygems_version: 3.2.15
79
80
  signing_key:
80
81
  specification_version: 4
81
82
  summary: caching of counts