Sha256: fed90d844c746a11234c74ed1135055718c63fb9263d9c93211357ecbcb81810
Contents?: true
Size: 1.34 KB
Versions: 34
Compression:
Stored size: 1.34 KB
Contents
module Flydata module QueryBasedSync class RecordSizeEstimator # Data size for the static part of sent record # {"row":{},"type":"update","respect_order":true, # "src_pos":"10051:10051:\t10520:10052:\t{\"id\":\"1000000000\"}", # "v":2,"seq":10000000,"table_name":"","table_rev":1} BASE_DATA_SIZE = 162 def initialize(table_name, num_columns) @base_record_size = calc_base_record_size(table_name, num_columns) end # Calculate a record size for emitting def calc_record_size(record) @base_record_size + record.values.inject(0){|r, v| r+=v.to_s.size} end private def calc_base_record_size(table_name, num_columns) col_cnt = num_columns # static part of {"1":"16","2":"cc", ...} col_size_for_static = 6 * col_cnt - 1 + 2 col_size_for_key = 0 col_cnt_length = col_cnt.to_s.size # get position of number, ex: 9->1, 12->2, 132->3 # calc size of each key per position, 1, 10x, 100x,... ex: 123 -> calc size 1-9 and 10-99 1.upto(col_cnt_length-1){|i| col_size_for_key += ( i * (10**i - (10**(i-1))) )} # calc size of the key for the hight position col_size_for_key += (col_cnt - 10**(col_cnt_length-1) + 1) * col_cnt_length col_size = col_size_for_static + col_size_for_key BASE_DATA_SIZE + table_name.size + col_size end end end end
Version data entries
34 entries across 34 versions & 1 rubygems