Class: Gitlab::ImportExport::FastHashSerializer::JSONBatchRelation
- Inherits:
-
Object
- Object
- Gitlab::ImportExport::FastHashSerializer::JSONBatchRelation
- Includes:
- Utils::StrongMemoize
- Defined in:
- lib/gitlab/import_export/fast_hash_serializer.rb
Overview
Usage of this class results in delayed serialization of relation. The serialization will be triggered when the ‘JSON.generate` is exected.
This class uses memory-optimised, lazily initialised, fast to recycle relation serialization.
The ‘JSON.generate` does use `#to_json`, that returns raw JSON content that is written directly to file.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(relation, options, preloads) ⇒ JSONBatchRelation
constructor
A new instance of JSONBatchRelation.
- #raw_json ⇒ Object
- #to_json(options = {}) ⇒ Object
Constructor Details
#initialize(relation, options, preloads) ⇒ JSONBatchRelation
Returns a new instance of JSONBatchRelation.
44 45 46 47 48 |
# File 'lib/gitlab/import_export/fast_hash_serializer.rb', line 44 def initialize(relation, , preloads) @relation = relation @options = @preloads = preloads end |
Instance Method Details
#as_json ⇒ Object
69 70 71 |
# File 'lib/gitlab/import_export/fast_hash_serializer.rb', line 69 def as_json(*) raise NotImplementedError end |
#raw_json ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/gitlab/import_export/fast_hash_serializer.rb', line 50 def raw_json strong_memoize(:raw_json) do result = +'' batch = @relation batch = batch.preload(@preloads) if @preloads batch.each do |item| result.concat(",") unless result.empty? result.concat(item.to_json(@options)) end result end end |
#to_json(options = {}) ⇒ Object
65 66 67 |
# File 'lib/gitlab/import_export/fast_hash_serializer.rb', line 65 def to_json( = {}) raw_json end |