ActsAsFastNestedSet 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/lib/acts_as_fast_nested_set.rb +19 -1
  3. metadata +3 -3
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ Hoe.new('ActsAsFastNestedSet', Adocca::Acts::ActsAsFastNestedSet::VERSION) do |p
11
11
  p.author = 'adocca Entertainment AB'
12
12
  # p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
13
13
  # p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
14
- p.extra_deps << ['AdoccaMemcache', '>= 0.1.0']
14
+ p.extra_deps << ['AdoccaMemcache', '>= 0.1.4']
15
15
  p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
16
16
  end
17
17
 
@@ -54,7 +54,7 @@ require 'active_record'
54
54
  module Adocca
55
55
  module Acts
56
56
  module ActsAsFastNestedSet
57
- VERSION = "0.1.2"
57
+ VERSION = "0.1.3"
58
58
 
59
59
  def self.append_features(base)
60
60
  super
@@ -97,6 +97,7 @@ module Adocca
97
97
  end
98
98
  end
99
99
  after_save descendant_invalidation_proc
100
+ after_save :unlock_nodeid_lock
100
101
  after_destroy descendant_invalidation_proc
101
102
  end
102
103
  end
@@ -109,6 +110,19 @@ module Adocca
109
110
  end
110
111
  end
111
112
  module InstanceMethods
113
+ #
114
+ # Get a String suitable for using as a Memcache lock when creating a nodeid.
115
+ #
116
+ def get_uniqueness_key
117
+ options = self.class.get_options
118
+ uniqueness_key = "acts_as_fast_nested_set:nodeid_lock:"
119
+ if options[:uniqueness_scope]
120
+ options[:uniqueness_scope].each do |col|
121
+ uniqueness_key << "#{self.send(col)}:"
122
+ end
123
+ end
124
+ return uniqueness_key
125
+ end
112
126
  #
113
127
  # Returns the entire thread
114
128
  #
@@ -153,6 +167,9 @@ module Adocca
153
167
 
154
168
  private
155
169
 
170
+ def unlock_nodeid_lock
171
+ CACHE.unlock(get_uniqueness_key) if @locked_nodeid
172
+ end
156
173
  def unique_statement
157
174
  self.class.get_options[:uniqueness_scope].nil? ? "" : "#{self.class.get_options[:uniqueness_scope].join(" = ? AND ")} = ?"
158
175
  end
@@ -169,6 +186,7 @@ module Adocca
169
186
 
170
187
  def ensure_node_id
171
188
  if self.node_id.nil? || self.node_id.empty?
189
+ @locked_nodeid = CACHE.lock(self.get_uniqueness_key, :expire => 10, :timeout => 10)
172
190
  if self.parent
173
191
  self.node_id = "#{self.parent.node_id}#{next_node_id(self.parent.node_id)}."
174
192
  else
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: ActsAsFastNestedSet
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.2
7
- date: 2006-12-22 00:00:00 +01:00
6
+ version: 0.1.3
7
+ date: 2007-01-17 00:00:00 +01:00
8
8
  summary: Fast nested set, really fast!
9
9
  require_paths:
10
10
  - lib
@@ -64,5 +64,5 @@ dependencies:
64
64
  requirements:
65
65
  - - ">="
66
66
  - !ruby/object:Gem::Version
67
- version: 0.1.0
67
+ version: 0.1.4
68
68
  version: