ruby on rails - what is the maximum amount of flags flag_shih_tzu can handle? -


i'm using "flag_shih_tzu" gem , want know maximum amount of flags can handle, or depend on int. length in flags column?
need handle 64 flags.
can it?

i maintainer of flag_shih_tzu.

best practice: each column used flags should have @ 16 flags set, performance reasons. find performance suffers columns holding more 16 flags.

workaround: single table can have multiple flag columns.

i create design follows:

 class foo ...    has_flags 1 => :is_a1,             # ... snip ...             16 => :is_a16,             :column => 'flag_col_a'    has_flags 1 => :is_b1,             # ... snip ...             16 => :is_b16,             :column => 'flag_col_b'    has_flags 1 => :is_c1,             # ... snip ...             16 => :is_c16,             :column => 'flag_col_c'    has_flags 1 => :is_d1,             # ... snip ...             16 => :is_d16,             :column => 'flag_col_d' end 

now when have instance of foo:

 foo = foo.new foo.is_d16 = false foo.save 

now can retrieve foo this:

 foo.not_is_d16 # => [foo] 

and if want check other flags in same query should chain conditions (in bitwise optimized manner) follows:

 foo.chained_flags_with(:not_is_d16, :is_d1, :is_d4, :not_is_d11, :is_d14) # => array of foo objects matching conditions 

now giant caveat! if want use 4 columns need in separate parts of sql clause, , in different active record relations.

important chained flags can chained flags same column.

 foo.   chained_flags_with(:not_is_a1, :is_a2).  # flag_col_a   chained_flags_with(:not_is_b3, :is_b4).  # flag_col_b   chained_flags_with(:not_is_c8, :is_c11). # flag_col_c   chained_flags_with(:not_is_d13, :is_d14) # flag_col_d 

personally, never go past 8 flags per column, , split flags many columns need.

recommendation: combine flags properties queried on same column, make best use of bitwise arithmetic.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -