Method: DrbListModel#rows_changed

Defined in:
lib/DrbDB/DrbListModel.rb

#rows_changed(chids, nick = nil, chseq = 0) ⇒ Object



480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
# File 'lib/DrbDB/DrbListModel.rb', line 480

def rows_changed(chids,nick=nil,chseq=0)
	ids=if chids.class.name == "Array" then chids.clone else [chids] end
	#prevent circular calling of rows_changed
	chseq=Time.new.to_f-@my_id  if chseq == 0 #FIXME: not unique

#		edebug("rows_changed:@#{chseq}:#{nick}:#{ids.inspect}")
	ids_to_remove=Array.new
	ids.each{|ch_id|
		if @last_seq[ch_id] == chseq
			ids_to_remove.push(ch_id)
		else
			@last_seq[ch_id]=chseq
		end
	}
	ids_to_remove.each{|to_rem| ids.delete(to_rem)}

	return unless ids.size > 0

	#precaching related ids, thus if update deletes a row, we still have the required data to walk the map
	pre_ids=Hash.new
	@drbdb.moditems_with_base(base){|other_list|
		unless other_list == self
			pre_ids[other_list]=Array.new unless pre_ids.has_key?(other_list)
			ids.each{|i| pre_ids[other_list].push(i)}
		end
	}

	@relations.each{|relation|
		if (relation['src_table'] == base) || (relation['dst_table'] == base && relation['rel_type'] == 'o')
			#forward, update parent lists for group_by queries
			#update lists with relation.src_table.src_field == relation.dst_table.dst_field
			@drbdb.moditems_with_base(relation['dst_table']){|other_list|
				pre_ids[other_list]=Array.new unless pre_ids.has_key?(other_list) #might already be there if multiple relations to each other
				ids.each{|changed_id|
					if other_id=data_of_column(relation['src_table']+"."+relation['src_field'],changed_id)
						pre_ids[other_list].push(other_id.to_i)
					end
				}
			}
			#else
			#reverse, update client lists, should be used only if this relation_id is used in the client query
			#update lists with dst_field == src_table.src_field
		end
	}
	
	rnick=if nick.nil? then nil else nick.clone end
	ids=update(nil,ids,rnick)

	#postcaching again, if update was insert we have the data to walk the map
	@relations.each{|relation|
		if (relation['src_table'] == base) || (relation['dst_table'] == base && relation['rel_type'] == 'o')
			#forward, update parent lists for group_by queries
			#update lists with relation.src_table.src_field == relation.dst_table.dst_field
			@drbdb.moditems_with_base(relation['dst_table']){|other_list|
				pre_ids[other_list]=Array.new unless pre_ids.has_key?(other_list) #might already be there
				ids.each{|changed_id|
					if other_id=data_of_column(relation['src_table']+"."+relation['src_field'],changed_id)
						pre_ids[other_list].push(other_id.to_i)
					end
				}
#					ecode("postcache #{other_list}:#{pre_ids[other_list].inspect}")
			}
			#else
			#reverse, update client lists, should be used only if this relation_id is used in the client query
			#update lists with dst_field == src_table.src_field
		end
	}
#		ecode("notifying other drblists with base:#{@base} for #{ids.inspect}")
	@drbdb.moditems_with_base(base){|other_list|
		#drblist.rows_changed(ids,nil,chseq) unless drblist == self
		unless other_list == self
			pre_ids[other_list]=Array.new unless pre_ids.has_key?(other_list)
			ids.each{|i| pre_ids[other_list].push(i)}
#				ecode("postcache #{other_list}:#{pre_ids[other_list].inspect}")
		end
	}

#		ecode("notifying other drblists related to:#{@base} for #{ids.inspect}")
#		ecode("pre_ids:#{pre_ids.inspect}")
	pre_ids.each{|other_model,other_ids|
		other_ids.uniq!
#			ecode("#{other_model}:#{other_ids.inspect}/@#{chseq}")
		other_model.rows_changed(other_ids,nil,chseq)
	}
end