summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2018-11-27 15:10:40 +0000
committerPhil Hughes <me@iamphill.com>2018-11-27 15:10:40 +0000
commit50e21a89a0009813b9f090288b22c64c5cefbd58 (patch)
tree7a142c12573f872f14ac366ec00082c650664592 /lib
parent15b4a8f93aaf313b8197ca381f529b00bd231a20 (diff)
downloadgitlab-ce-50e21a89a0009813b9f090288b22c64c5cefbd58.tar.gz
Suggests issues when typing title
This suggests possibly related issues when the user types a title. This uses GraphQL to allow the frontend to request the exact data that is requires. We also get free caching through the Vue Apollo plugin. With this we can include the ability to import .graphql files in JS and Vue files. Also we now have the Vue test utils library to make testing Vue components easier. Closes #22071
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/graphql/loaders/batch_model_loader.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/gitlab/graphql/loaders/batch_model_loader.rb b/lib/gitlab/graphql/loaders/batch_model_loader.rb
new file mode 100644
index 00000000000..5a0099dc6b1
--- /dev/null
+++ b/lib/gitlab/graphql/loaders/batch_model_loader.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Graphql
+ module Loaders
+ class BatchModelLoader
+ attr_reader :model_class, :model_id
+
+ def initialize(model_class, model_id)
+ @model_class, @model_id = model_class, model_id
+ end
+
+ # rubocop: disable CodeReuse/ActiveRecord
+ def find
+ BatchLoader.for({ model: model_class, id: model_id }).batch do |loader_info, loader|
+ per_model = loader_info.group_by { |info| info[:model] }
+ per_model.each do |model, info|
+ ids = info.map { |i| i[:id] }
+ results = model.where(id: ids)
+
+ results.each { |record| loader.call({ model: model, id: record.id }, record) }
+ end
+ end
+ end
+ # rubocop: enable CodeReuse/ActiveRecord
+ end
+ end
+ end
+end