summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2017-08-16 18:34:55 +0000
committerJose Ivan Vargas <jvargas@gitlab.com>2017-08-18 11:50:35 -0500
commit3cb4352b0141d6471cfedffb646ecd4ff6d42b9a (patch)
treee8ac14daa4bef967db560a82c89825bd8c06673d /config
parentf34faaba7c75bfc15f9995ef45dc78512a5b6932 (diff)
downloadgitlab-ce-3cb4352b0141d6471cfedffb646ecd4ff6d42b9a.tar.gz
Merge branch 'dm-gpg-signature-performance' into 'master'
Only create commit GPG signature when necessary See merge request !13561
Diffstat (limited to 'config')
-rw-r--r--config/initializers/active_record_array_type_casting.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/config/initializers/active_record_array_type_casting.rb b/config/initializers/active_record_array_type_casting.rb
new file mode 100644
index 00000000000..d94d592add6
--- /dev/null
+++ b/config/initializers/active_record_array_type_casting.rb
@@ -0,0 +1,20 @@
+module ActiveRecord
+ class PredicateBuilder
+ class ArrayHandler
+ module TypeCasting
+ def call(attribute, value)
+ # This is necessary because by default ActiveRecord does not respect
+ # custom type definitions (like our `ShaAttribute`) when providing an
+ # array in `where`, like in `where(commit_sha: [sha1, sha2, sha3])`.
+ model = attribute.relation&.engine
+ type = model.user_provided_columns[attribute.name] if model
+ value = value.map { |value| type.type_cast_for_database(value) } if type
+
+ super(attribute, value)
+ end
+ end
+
+ prepend TypeCasting
+ end
+ end
+end