@@ -6,39 +6,38 @@ module ActiveRecord
66 # adds method to get the HyperMesh public column types
77 # this works because the public folder is currently required to be eager loaded.
88 class Base
9+ @@hyper_stack_public_columns_hash_mutex = Mutex . new
910 def self . public_columns_hash
10- return @public_columns_hash if @public_columns_hash && Rails . env . production?
11- files = [ ]
12- Hyperstack . public_model_directories . each do |dir |
13- dir_length = Rails . root . join ( dir ) . to_s . length + 1
14- Dir . glob ( Rails . root . join ( dir , '**' , '*.rb' ) ) . each do |file |
15- require_dependency ( file ) # still the file is loaded to make sure for development and test env
16- files << file [ dir_length ..-4 ]
11+ @@hyper_stack_public_columns_hash_mutext . synchronize do
12+ return @public_columns_hash if @public_columns_hash && Rails . env . production?
13+ files = [ ]
14+ Hyperstack . public_model_directories . each do |dir |
15+ dir_length = Rails . root . join ( dir ) . to_s . length + 1
16+ Dir . glob ( Rails . root . join ( dir , '**' , '*.rb' ) ) . each do |file |
17+ require_dependency ( file ) # still the file is loaded to make sure for development and test env
18+ files << file [ dir_length ..-4 ]
19+ end
1720 end
18- end
19- @public_columns_hash = { }
20- # descendants only works for already loaded models!
21- descendants . each do | model |
22- if files . include? ( model . name . underscore ) && model . name . underscore != 'application_record'
23- @public_columns_hash [ model . name ] = model . columns_hash rescue nil # why rescue?
21+ @public_columns_hash = { }
22+ # descendants only works for already loaded models!
23+ descendants . each do | model |
24+ if files . include? ( model . name . underscore ) && model . name . underscore != 'application_record'
25+ @public_columns_hash [ model . name ] = model . columns_hash rescue nil # why rescue?
26+ end
2427 end
25- # begin
26- # @public_columns_hash[model.name] = model.columns_hash if model.table_name
27- # rescue Exception => e
28- # binding.pry
29- # @public_columns_hash = nil
30- # raise $!, "Could not read 'columns_hash' for #{model}: #{$!}", $!.backtrace
31- # end if files.include?(model.name.underscore) && model.name.underscore != 'application_record'
28+ @public_columns_hash
3229 end
33- @public_columns_hash
3430 end
3531
32+ @@hyper_stack_public_columns_hash_as_json_mutex = Mutex . new
3633 def self . public_columns_hash_as_json
37- return @public_columns_hash_json if @public_columns_hash_json && Rails . env . production?
38- pch = public_columns_hash
39- return @public_columns_hash_json if @prev_public_columns_hash == pch
40- @prev_public_columns_hash = pch
41- @public_columns_hash_json = pch . to_json
34+ @@hyper_stack_public_columns_hash_as_json_mutex . synchronize do
35+ return @public_columns_hash_json if @public_columns_hash_json && Rails . env . production?
36+ pch = public_columns_hash
37+ return @public_columns_hash_json if @prev_public_columns_hash == pch
38+ @prev_public_columns_hash = pch
39+ @public_columns_hash_json = pch . to_json
40+ end
4241 end
4342 end
4443end
0 commit comments