Class: Gitlab::ImportExport::JSON::NdjsonReader

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/import_export/json/ndjson_reader.rb

Constant Summary collapse

MAX_JSON_DOCUMENT_SIZE =
50.megabytes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir_path) ⇒ NdjsonReader

Returns a new instance of NdjsonReader.


11
12
13
14
# File 'lib/gitlab/import_export/json/ndjson_reader.rb', line 11

def initialize(dir_path)
  @dir_path = dir_path
  @consumed_relations = Set.new
end

Instance Attribute Details

#dir_pathObject (readonly)

Returns the value of attribute dir_path


9
10
11
# File 'lib/gitlab/import_export/json/ndjson_reader.rb', line 9

def dir_path
  @dir_path
end

Instance Method Details

#consume_attributes(importable_path) ⇒ Object


25
26
27
28
29
30
# File 'lib/gitlab/import_export/json/ndjson_reader.rb', line 25

def consume_attributes(importable_path)
  # This reads from `tree/project.json`
  path = file_path("#{importable_path}.json")
  data = File.read(path, MAX_JSON_DOCUMENT_SIZE)
  json_decode(data)
end

#consume_relation(importable_path, key) ⇒ Object


32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gitlab/import_export/json/ndjson_reader.rb', line 32

def consume_relation(importable_path, key)
  Enumerator.new do |documents|
    next unless @consumed_relations.add?("#{importable_path}/#{key}")

    # This reads from `tree/project/merge_requests.ndjson`
    path = file_path(importable_path, "#{key}.ndjson")
    next unless File.exist?(path)

    File.foreach(path, MAX_JSON_DOCUMENT_SIZE).with_index do |line, line_num|
      documents << [json_decode(line), line_num]
    end
  end
end

#exist?Boolean

Returns:

  • (Boolean)

16
17
18
# File 'lib/gitlab/import_export/json/ndjson_reader.rb', line 16

def exist?
  Dir.exist?(@dir_path)
end

#legacy?Boolean

This can be removed once legacy_reader is deprecated.

Returns:

  • (Boolean)

21
22
23
# File 'lib/gitlab/import_export/json/ndjson_reader.rb', line 21

def legacy?
  false
end