card 1.16.10 → 1.16.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ffc60ca121686905da93e8d2689061d3280c975
4
- data.tar.gz: 29aa48d586a15e9016e4629ff5f7dde792d9d000
3
+ metadata.gz: 87ac13203770cb0105dca6d10755c9f442425230
4
+ data.tar.gz: 4f27287e05a9cb4ed93e0dd18a64585d47b9f044
5
5
  SHA512:
6
- metadata.gz: 01618a961f3ade1621804f6f395125c12b1e4cc9c224f2b63f5b4d27dce4bb437a3c639aded2b43e8dd776ae67e31a5a40a898751ef4eaedb72b39b0efe74576
7
- data.tar.gz: b03556e07938200a5672dae4d4173f2f8c6cffba4157eec963326fa566ab179018990fad69f70a1b1f212d160f675e61fc92af2bccea6bdee87a593b8475150b
6
+ metadata.gz: 94d18bfbd1b5ffc9ae65f3cc503006571569b9a2b483bfe2b412b7d73d760e121d34dacd23e36bd21930e03145e943e9e29863f8fedbe96884d6b204e4ce5a0b
7
+ data.tar.gz: 6d01d13ce7cd4e0c3e0a88414ee9f384e1ce9641189a54bcf0e032dae75f3decfb2371a7e3bba8e77a3546cb026bbdbc0a8998b5a48e53162e8b44eb7c6e3581
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.16.10
1
+ 1.16.11
@@ -0,0 +1,6 @@
1
+ class MoreSpaceForDbContent < ActiveRecord::Migration
2
+ def change
3
+ change_column :cards, :db_content, :text, limit: 1.megabyte
4
+ change_column :card_changes, :value, :text, limit: 1.megabyte
5
+ end
6
+ end
@@ -4,19 +4,26 @@ class AddListCards < Card::CoreMigration
4
4
  def up
5
5
  create_card! name: 'List', codename: :list,
6
6
  type_code: :cardtype
7
+
7
8
  create_card! name: 'Listed by', codename: :listed_by,
8
9
  type_code: :cardtype
9
- create_card! name: '*cached count', codename: :cached_count,
10
- subcards: {
11
- '+*right+*update'=>'[[Administrator]]',
12
- '+*right+*create'=>'[[Administrator]]',
13
- '+*right+*delete'=>'[[Administrator]]'
14
- }
15
- create_card! name: '*cached content', codename: :cached_content,
16
- subcards: {
17
- '+*right+*update'=>'[[Administrator]]',
18
- '+*right+*create'=>'[[Administrator]]',
19
- '+*right+*delete'=>'[[Administrator]]'
20
- }
10
+
11
+ create_or_update name: '*cached count',
12
+ codename: :cached_count,
13
+ rename_if_conflict: false,
14
+ subcards: {
15
+ '+*right+*update' => '[[Administrator]]',
16
+ '+*right+*create' => '[[Administrator]]',
17
+ '+*right+*delete' => '[[Administrator]]'
18
+ }
19
+
20
+ create_or_update name: '*cached content',
21
+ codename: :cached_content,
22
+ rename_if_conflict: false,
23
+ subcards: {
24
+ '+*right+*update' => '[[Administrator]]',
25
+ '+*right+*create' => '[[Administrator]]',
26
+ '+*right+*delete' => '[[Administrator]]'
27
+ }
21
28
  end
22
29
  end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20150724210803) do
14
+ ActiveRecord::Schema.define(version: 20151105225559) do
15
15
 
16
16
  create_table "card_actions", force: :cascade do |t|
17
17
  t.integer "card_id", limit: 4
@@ -38,7 +38,7 @@ ActiveRecord::Schema.define(version: 20150724210803) do
38
38
  create_table "card_changes", force: :cascade do |t|
39
39
  t.integer "card_action_id", limit: 4
40
40
  t.integer "field", limit: 4
41
- t.text "value", limit: 65535
41
+ t.text "value", limit: 16777215
42
42
  end
43
43
 
44
44
  add_index "card_changes", ["card_action_id"], name: "card_changes_card_action_id_index", using: :btree
@@ -66,22 +66,22 @@ ActiveRecord::Schema.define(version: 20150724210803) do
66
66
  add_index "card_revisions", ["creator_id"], name: "revisions_created_by_index", using: :btree
67
67
 
68
68
  create_table "cards", force: :cascade do |t|
69
- t.string "name", limit: 255, null: false
70
- t.string "key", limit: 255, null: false
69
+ t.string "name", limit: 255, null: false
70
+ t.string "key", limit: 255, null: false
71
71
  t.string "codename", limit: 255
72
72
  t.integer "left_id", limit: 4
73
73
  t.integer "right_id", limit: 4
74
74
  t.integer "current_revision_id", limit: 4
75
- t.datetime "created_at", null: false
76
- t.datetime "updated_at", null: false
77
- t.integer "creator_id", limit: 4, null: false
78
- t.integer "updater_id", limit: 4, null: false
75
+ t.datetime "created_at", null: false
76
+ t.datetime "updated_at", null: false
77
+ t.integer "creator_id", limit: 4, null: false
78
+ t.integer "updater_id", limit: 4, null: false
79
79
  t.string "read_rule_class", limit: 255
80
80
  t.integer "read_rule_id", limit: 4
81
81
  t.integer "references_expired", limit: 4
82
- t.boolean "trash", null: false
83
- t.integer "type_id", limit: 4, null: false
84
- t.text "db_content", limit: 65535
82
+ t.boolean "trash", null: false
83
+ t.integer "type_id", limit: 4, null: false
84
+ t.text "db_content", limit: 16777215
85
85
  end
86
86
 
87
87
  add_index "cards", ["key"], name: "cards_key_index", unique: true, using: :btree
@@ -1 +1 @@
1
- 20150724210803
1
+ 20151105225559
@@ -5,7 +5,7 @@ module Card::ActiveRecordHelper
5
5
  end
6
6
 
7
7
  def create_card! args
8
- create_card args.merge(rename_if_conflict: :other)
8
+ create_card args.reverse_merge(rename_if_conflict: :new)
9
9
  end
10
10
 
11
11
  def update_card name, args
@@ -14,7 +14,7 @@ module Card::ActiveRecordHelper
14
14
  end
15
15
 
16
16
  def update_card! args
17
- update_card args.merge(resolve_name_conflict: :other)
17
+ update_card args.reverse_merge(rename_if_conflict: :new)
18
18
  end
19
19
 
20
20
  def create_or_update name_or_args, args=nil
@@ -23,22 +23,20 @@ module Card::ActiveRecordHelper
23
23
  if Card[name]
24
24
  update_card name, args
25
25
  else
26
- create_card args.merge(:name=>name)
26
+ create_card args.merge(name: name)
27
27
  end
28
28
  end
29
29
 
30
30
  def create_or_update! name_or_args, args=nil
31
- if args
32
- args[:resolve_name_conflict] = :other
33
- else
34
- name_or_args[:resolve_name_conflict] = :other
35
- end
36
- create_or_update name_or_args, args
31
+ name = args ? name_or_args : name_or_args[:name]
32
+ args ||= {}
33
+ create_or_update name, args.reverse_merge(rename_if_conflict: :new)
37
34
  end
38
35
 
39
36
  def resolve_name_conflict args
40
- if (rename = args.delete :rename_if_conflict)
41
- args[:name] = Card.uniquify_name args[:name], rename == :other
37
+ rename = args.delete :rename_if_conflict
38
+ if rename
39
+ args[:name] = Card.uniquify_name args[:name], rename
42
40
  end
43
41
  end
44
42
  end
@@ -54,11 +54,13 @@ class Card
54
54
  end
55
55
 
56
56
  def generate_cache_id
57
- ((Time.now.to_f * 100).to_i).to_s + ('a'..'z').to_a[rand(26)] + ('a'..'z').to_a[rand(26)]
57
+ ((Time.now.to_f * 100).to_i).to_s +
58
+ ('a'..'z').to_a[rand(26)] +
59
+ ('a'..'z').to_a[rand(26)]
58
60
  end
59
61
 
60
62
  def reset_global
61
- cache_by_class.each do |klass, cache|
63
+ cache_by_class.each do |_klass, cache|
62
64
  cache.reset hard=true
63
65
  end
64
66
  Card::Codename.reset_cache
@@ -67,9 +69,11 @@ class Card
67
69
 
68
70
  def reset_local
69
71
  cache_by_class.each do |cc, cache|
70
- if Card::Cache===cache
72
+ if Card::Cache === cache
71
73
  cache.reset_local
72
- else warn "reset class #{cc}, #{cache.class} #{caller[0..8]*"\n"} ???" end
74
+ else
75
+ warn "reset class #{cc}, #{cache.class} #{caller[0..8] * "\n"} ???"
76
+ end
73
77
  end
74
78
  end
75
79
 
@@ -91,20 +95,16 @@ class Card
91
95
  private
92
96
 
93
97
  def prepopulate
94
- if @@prepopulating
95
- @@rule_cache ||= Card.rule_cache
96
- @@read_rule_cache ||= Card.read_rule_cache
97
- @@user_ids_cache ||= Card.user_ids_cache
98
- @@rule_keys_cache ||= Card.rule_keys_cache
99
- Card.cache.write_local 'RULES', @@rule_cache
100
- Card.cache.write_local 'READRULES', @@read_rule_cache
101
- Card.cache.write_local 'USER_IDS', @@user_ids_cache
102
- Card.cache.write_local 'RULE_KEYS', @@rule_keys_cache
103
- end
98
+ return unless @@prepopulating
99
+ @@rule_cache ||= Card.rule_cache
100
+ @@user_ids_cache ||= Card.user_ids_cache
101
+ @@read_rule_cache ||= Card.read_rule_cache
102
+ @@rule_keys_cache ||= Card.rule_keys_cache
103
+ Card.cache.write_local 'RULES', @@rule_cache
104
+ Card.cache.write_local 'READRULES', @@read_rule_cache
105
+ Card.cache.write_local 'USER_IDS', @@user_ids_cache
106
+ Card.cache.write_local 'RULE_KEYS', @@rule_keys_cache
104
107
  end
105
-
106
-
107
-
108
108
  end
109
109
 
110
110
  attr_reader :prefix, :store, :klass
@@ -179,7 +179,7 @@ class Card
179
179
 
180
180
  def delete key
181
181
  @store.delete(@prefix + key) if @store
182
- @local.delete key
182
+ delete_local key
183
183
  end
184
184
 
185
185
  def delete_local key
@@ -210,10 +210,9 @@ module ClassMethods
210
210
  end
211
211
 
212
212
  def write_to_local_cache card
213
- if Card.cache
214
- Card.cache.write_local card.key, card
215
- Card.cache.write_local "~#{card.id}", card.key if card.id && card.id != 0
216
- end
213
+ return unless Card.cache
214
+ Card.cache.write_local card.key, card
215
+ Card.cache.write_local "~#{card.id}", card.key if card.id && card.id != 0
217
216
  end
218
217
 
219
218
  def expand_mark mark, opts
@@ -242,7 +241,7 @@ module ClassMethods
242
241
  end
243
242
  end
244
243
 
245
- def fullname_from_name name, new_opts = {}
244
+ def fullname_from_name name, new_opts={}
246
245
  if new_opts && supercard = new_opts[:supercard]
247
246
  name.to_name.to_absolute_name supercard.name
248
247
  else
@@ -253,16 +252,17 @@ end
253
252
 
254
253
  # ~~~~~~~~~~ Instance ~~~~~~~~~~~~~
255
254
 
256
- def fetch opts = {}
257
- if traits = opts.delete(:trait)
258
- traits = Array.wrap traits
259
- traits.inject(self) do |card, trait|
260
- Card.fetch card.cardname.trait(trait), opts
261
- end
255
+ def fetch opts={}
256
+ traits = opts.delete(:trait)
257
+ return unless traits
258
+ # should this fail as an incorrect api call?
259
+ traits = Array.wrap traits
260
+ traits.inject(self) do |card, trait|
261
+ Card.fetch card.cardname.trait(trait), opts
262
262
  end
263
263
  end
264
264
 
265
- def renew args = {}
265
+ def renew args={}
266
266
  opts = args[:new].clone
267
267
  opts[:name] ||= cardname
268
268
  opts[:skip_modules] = args[:skip_modules]
@@ -275,7 +275,7 @@ def expire_pieces
275
275
  end
276
276
  end
277
277
 
278
- def expire subcards = false
278
+ def expire subcards=false
279
279
  # Rails.logger.warn "expiring i:#{id}, #{inspect}"
280
280
  if subcards
281
281
  expire_subcards
@@ -286,7 +286,7 @@ def expire subcards = false
286
286
  Card.cache.delete "~#{id}" if id
287
287
  end
288
288
 
289
- def refresh force = false
289
+ def refresh force=false
290
290
  if force || self.frozen? || self.readonly?
291
291
  fresh_card = self.class.find id
292
292
  fresh_card.include_set_modules
@@ -308,4 +308,3 @@ def rename_from_mark mark
308
308
  return unless mark && mark.to_s != name
309
309
  self.name = mark.to_s
310
310
  end
311
-
@@ -1,18 +1,20 @@
1
1
  require 'uuid'
2
2
 
3
3
  module ClassMethods
4
- def uniquify_name name, rename=false
5
- return name unless Card[name]
4
+ def uniquify_name name, rename=:new
5
+ return name unless Card.exists?(name)
6
6
  uniq_name = "#{name} 1"
7
- while Card[uniq_name]
7
+ while Card.exists?(uniq_name)
8
8
  uniq_name.next!
9
9
  end
10
- return uniq_name unless rename
11
-
12
- Card[name].update_attributes! name: uniq_name,
13
- update_referencers: true
14
- # name conflict resolved; original name can be used
15
- name
10
+ if rename == :old
11
+ # name conflict resolved; original name can be used
12
+ Card[name].update_attributes! name: uniq_name,
13
+ update_referencers: true
14
+ name
15
+ else
16
+ uniq_name
17
+ end
16
18
  end
17
19
  end
18
20
 
@@ -120,23 +122,32 @@ def left_or_new args={}
120
122
  end
121
123
 
122
124
  def children
123
- Card.search((simple? ? :part : :left) => name).to_a
125
+ children_names.map { |name| Card[name] }
124
126
  end
125
127
 
126
- def dependents
127
- return [] if new_card?
128
+ def children_names parent_name=nil
129
+ # eg, A+B is a child of A and B
130
+ parent_name ||= name
131
+ field = parent_name.to_name.simple? ? :part : :left
132
+ Card.search field => parent_name, return: :name
133
+ end
128
134
 
129
- if @dependents.nil?
130
- @dependents =
131
- Auth.as_bot do
132
- deps = children
133
- deps.inject(deps) do |array, card|
134
- array + card.dependents
135
- end
136
- end
137
- # Rails.logger.warn "dependents[#{inspect}] #{@dependents.inspect}"
135
+ def descendant_names parent_name=nil
136
+ return [] if new_card?
137
+ parent_name ||= name
138
+ Auth.as_bot do
139
+ deps = children_names parent_name
140
+ deps.inject(deps) do |array, childname|
141
+ array + descendant_names(childname)
142
+ end
138
143
  end
139
- @dependents
144
+ end
145
+
146
+ def descendants
147
+ # children and children's children
148
+ # NOTE - set modules are not loaded
149
+ # -- should only be used for name manipulations
150
+ @descendants ||= descendant_names.map { |name| Card.quick_fetch name }
140
151
  end
141
152
 
142
153
  def repair_key
@@ -154,7 +165,7 @@ def repair_key
154
165
  saved ||= (self.cardname = current_key) && self.save!
155
166
 
156
167
  if saved
157
- dependents.each(&:repair_key)
168
+ descendants.each(&:repair_key)
158
169
  else
159
170
  Rails.logger.debug "FAILED TO REPAIR BROKEN KEY: #{key}"
160
171
  self.name = "BROKEN KEY: #{name}"
@@ -275,28 +286,25 @@ event :cascade_name_changes, after: :store, on: :update, changed: :name do
275
286
  self.update_referencers = false if update_referencers == 'false'
276
287
  Card::Reference.update_on_rename self, name, self.update_referencers
277
288
 
278
- deps = dependents
279
- # warn "-------------------#{name_was}---- CASCADE #{self.name} -> deps: " \
280
- # " #{deps.map(&:name)*', '} -----------------------"
281
-
282
- @dependents = nil # reset
289
+ des = descendants
290
+ @descendants = nil # reset
283
291
 
284
- deps.each do |dep|
292
+ des.each do |de|
285
293
  # here we specifically want NOT to invoke recursive cascades on these
286
294
  # cards, have to go this low level to avoid callbacks.
287
- Rails.logger.info "cascading name: #{dep.name}"
288
- Card.expire dep.name # old name
289
- newname = dep.cardname.replace_part name_was, name
290
- Card.where(id: dep.id).update_all name: newname.to_s, key: newname.key
291
- Card::Reference.update_on_rename dep, newname, update_referencers
295
+ Rails.logger.info "cascading name: #{de.name}"
296
+ Card.expire de.name # old name
297
+ newname = de.cardname.replace_part name_was, name
298
+ Card.where(id: de.id).update_all name: newname.to_s, key: newname.key
299
+ Card::Reference.update_on_rename de, newname, update_referencers
292
300
  Card.expire newname
293
301
  end
294
- execute_referencers_update(deps) if update_referencers
302
+ execute_referencers_update(des) if update_referencers
295
303
  end
296
304
 
297
- def execute_referencers_update dependents
305
+ def execute_referencers_update descendants
298
306
  Auth.as_bot do
299
- [name_referencers(name_was) + dependents.map(&:referencers)]
307
+ [name_referencers(name_was) + descendants.map(&:referencers)]
300
308
  .flatten.uniq.each do |card|
301
309
  # FIXME: using 'name_referencers' instead of plain 'referencers' for self
302
310
  # because there are cases where trunk and tag
@@ -307,7 +315,7 @@ def execute_referencers_update dependents
307
315
  # so at this time X is still including Y, which does not exist.
308
316
  # therefore #referencers doesn't find it, but name_referencers(old_name)
309
317
  # does.
310
- # some even more complicated scenario probably breaks on the dependents,
318
+ # some even more complicated scenario probably breaks on the descendants,
311
319
  # so this probably needs a more thoughtful refactor
312
320
  # aligning the dependent saving with the name cascading
313
321
 
@@ -6,7 +6,7 @@ end
6
6
 
7
7
  def extended_referencers
8
8
  # FIXME .. we really just need a number here.
9
- (dependents + [self]).map(&:referencers).flatten.uniq
9
+ (descendants + [self]).map(&:referencers).flatten.uniq
10
10
  end
11
11
 
12
12
 
@@ -67,4 +67,4 @@ event :store_subcards, after: :store do
67
67
  # eg. <user> creates <user+*account> creates <user+*account+*status>
68
68
  # <user> changes <user+*account+*status> in event activate_account
69
69
  Card.write_to_local_cache self
70
- end
70
+ end