delfos 0.0.2.pre.rc2 → 0.0.2.pre.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/exe/delfos_import +38 -0
  3. data/exe/delfos_import_offline_queries +9 -0
  4. data/exe/delfos_update_distance +11 -0
  5. data/lib/delfos.rb +29 -73
  6. data/lib/delfos/config.rb +90 -0
  7. data/lib/delfos/config/inclusion.rb +90 -0
  8. data/lib/delfos/file_system.rb +7 -2
  9. data/lib/delfos/file_system/app_directories.rb +16 -18
  10. data/lib/delfos/file_system/app_files.rb +31 -0
  11. data/lib/delfos/file_system/file_cache.rb +21 -0
  12. data/lib/delfos/file_system/path_determination.rb +10 -7
  13. data/lib/delfos/method_trace.rb +18 -6
  14. data/lib/delfos/method_trace/call_handler.rb +6 -2
  15. data/lib/delfos/method_trace/code_location.rb +2 -12
  16. data/lib/delfos/method_trace/code_location/container_method_factory.rb +50 -25
  17. data/lib/delfos/method_trace/code_location/eval_in_caller.rb +2 -4
  18. data/lib/delfos/method_trace/code_location/filename_helpers.rb +1 -1
  19. data/lib/delfos/method_trace/code_location/method.rb +13 -9
  20. data/lib/delfos/neo4j.rb +12 -3
  21. data/lib/delfos/neo4j/distance/update.rb +1 -1
  22. data/lib/delfos/neo4j/live/call_site_logger.rb +27 -0
  23. data/lib/delfos/neo4j/offline.rb +13 -0
  24. data/lib/delfos/neo4j/offline/call_site_logger.rb +6 -1
  25. data/lib/delfos/neo4j/offline/importer.rb +8 -7
  26. data/lib/delfos/neo4j/query_execution/batch/execution.rb +93 -0
  27. data/lib/delfos/neo4j/query_execution/batch/retryable.rb +103 -0
  28. data/lib/delfos/neo4j/query_execution/errors.rb +4 -3
  29. data/lib/delfos/neo4j/query_execution/http.rb +1 -1
  30. data/lib/delfos/neo4j/query_execution/sync.rb +1 -1
  31. data/lib/delfos/neo4j/query_execution/transactional.rb +1 -1
  32. data/lib/delfos/neo4j/schema.rb +1 -1
  33. metadata +38 -16
  34. data/lib/delfos/neo4j/batch/execution.rb +0 -91
  35. data/lib/delfos/neo4j/batch/retryable.rb +0 -101
  36. data/lib/delfos/setup.rb +0 -120
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d7fee8925fceb4563ffc7f5895a63c2d3e372c06
4
- data.tar.gz: 444793d867d93a22502053420bec22c7c14cef79
3
+ metadata.gz: 2abc41e61012e7262afb07416943d0eac71811f3
4
+ data.tar.gz: 9015780c3ed0a18153c3eceb083914ac2bf23ee5
5
5
  SHA512:
6
- metadata.gz: 9424c15ce219468cadb02be9e35ce932bbba9cb103416dbb0eda9115b61943955e2eae1c5464296a255aa83ad7a8de9b985240c298d4d953009829696ab577b4
7
- data.tar.gz: ceb9b9bc4d27a011d46785b92a3d1c62294f0abce4f95e5d69fa1d8aadeee9178bf8abd971c3e8b71c0111005046f7758d92840d0dcae48db80481ea54eeae3f
6
+ metadata.gz: 521ee2c4de9433e74a6989caf6991c76fb0dc238b842a5444fe0dcca1a049c98d96670c755f63ed4bf71e1359c3a69257f0aac18106aad47cd8a46f4e7143204
7
+ data.tar.gz: d5b09f2278d2312707d11743a8156cb1de88fb44fcb76f6599a226e84f09b5c1d764d862e52af19b26ea9295aaacdf423ac713c269caca3b01670b64b6c3137d
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "fileutils"
5
+
6
+ # Credit to http://ruby-journal.com/how-to-import-millions-records-via-activerecord-within-minutes-not-hours/
7
+ # for the basis for this script
8
+
9
+ NUMBER_OF_SPLIT_LINES = 10_000
10
+ SPLIT_FILE_PREFIX = "delfos_queries_"
11
+ TEMP_DIRECTORY = "./tmp/delfos"
12
+ BIG_FILE_PATH = ARGV[0] || "./tmp/delfos/query_parameters.json"
13
+
14
+ BIG_FILENAME = File.basename BIG_FILE_PATH
15
+ FileUtils.rm_rf TEMP_DIRECTORY
16
+ FileUtils.mkdir_p TEMP_DIRECTORY
17
+ FileUtils.cp BIG_FILE_PATH, "#{TEMP_DIRECTORY}/#{BIG_FILENAME}"
18
+
19
+ FileUtils.cd TEMP_DIRECTORY
20
+
21
+ def split_file
22
+ puts "Split '#{BIG_FILENAME}' file into small chunks with size #{NUMBER_OF_SPLIT_LINES} lines"
23
+ system "split -l #{NUMBER_OF_SPLIT_LINES} #{BIG_FILENAME} #{SPLIT_FILE_PREFIX}"
24
+ end
25
+
26
+ def process_split_files
27
+ split_files = Dir.glob("#{SPLIT_FILE_PREFIX}*")
28
+
29
+ split_files.each do |f|
30
+ command = "FILE=#{f} delfos_import_offline_queries"
31
+ system command
32
+ end
33
+ end
34
+
35
+ split_file
36
+ process_split_files
37
+
38
+ system "delfos_update_distance"
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
5
+
6
+ require "delfos"
7
+
8
+ Delfos.configure
9
+ Delfos.import_offline_queries(ENV["FILE"])
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
5
+
6
+ require "delfos"
7
+
8
+ Delfos.configure { |c| c.include = "." }
9
+ Delfos.start!
10
+ Delfos.update_distance!
11
+ Delfos.finish!
@@ -1,103 +1,59 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "delfos/setup"
3
+ require "forwardable"
4
+
5
+ require "delfos/config"
6
+ require "delfos/method_trace"
7
+ require "delfos/neo4j"
4
8
 
5
9
  module Delfos
6
10
  class << self
7
- attr_accessor :application_directories,
11
+ extend Forwardable
12
+
13
+ def_delegators :config,
14
+ :batch_size,
15
+ :call_site_logger,
16
+ :logger,
17
+ :max_query_size,
8
18
  :offline_query_saving,
9
19
  :offline_query_filename
10
20
 
11
- attr_writer :logger, :neo4j, :batch_size, :max_query_size
12
-
13
- # rubocop:disable Metrics/ParameterLists
14
- def setup!(
15
- logger: nil,
16
- call_site_logger: nil,
17
- application_directories: nil,
18
- batch_size: nil,
19
- max_query_size: nil,
20
- offline_query_saving: nil
21
- )
22
- # rubocop:enable Metrics/ParameterLists
23
- self.logger = logger
24
- self.batch_size = batch_size
25
- self.max_query_size = max_query_size
21
+ attr_reader :config
26
22
 
27
- Setup.perform!(
28
- call_site_logger: call_site_logger,
29
- application_directories: application_directories,
30
- offline_query_saving: offline_query_saving,
31
- )
32
- end
33
-
34
- def import_offline_queries(filename)
35
- require "delfos/neo4j/offline/importer"
36
- Neo4j::Offline::Importer.new(filename).perform
23
+ def start!
24
+ ::Delfos::MethodTrace.enable!
37
25
  end
38
26
 
39
- def batch_size
40
- @batch_size ||= 100
41
- end
27
+ def finish!
28
+ ::Delfos::MethodTrace.disable!
42
29
 
43
- def max_query_size
44
- @max_query_size ||= 10_000
30
+ config.call_site_logger.finish!
45
31
  end
46
32
 
47
- def include_file?(file)
48
- require "delfos/file_system"
49
- FileSystem.include_file?(file)
33
+ def reset!
34
+ Delfos.config&.call_site_logger&.reset!
50
35
  end
51
36
 
52
- attr_writer :call_site_logger
53
-
54
- def call_site_logger
55
- @call_site_logger ||= Delfos::Setup.default_call_site_logger
56
- end
37
+ def configure
38
+ new_config
57
39
 
58
- def logger
59
- @logger ||= default_logger
40
+ yield config if block_given?
60
41
  end
61
42
 
62
- def neo4j
63
- setup_neo4j!
64
- end
65
-
66
- def setup_neo4j!
67
- require "delfos/neo4j"
68
- @neo4j ||= Neo4j.config
43
+ def import_offline_queries(filename)
44
+ Neo4j.import_offline_queries(filename)
69
45
  end
70
46
 
71
- def finish!
72
- if offline_query_saving
73
- Delfos.call_site_logger.finish!
74
- else
75
- flush!
76
- update_distance!
77
- disable!
78
- end
47
+ def include_file?(file)
48
+ config&.include?(file)
79
49
  end
80
50
 
81
51
  def update_distance!
82
- require "delfos/neo4j"
83
52
  Neo4j.update_distance!
84
53
  end
85
54
 
86
- def flush!
87
- require "delfos/neo4j"
88
- Neo4j.flush!
89
- end
90
-
91
- def disable!
92
- Setup.disable!
93
- end
94
-
95
- def default_logger
96
- require "logger"
97
-
98
- Logger.new(STDOUT).tap do |l|
99
- l.level = Logger::ERROR
100
- end
55
+ def new_config
56
+ @config ||= Delfos::Config.new
101
57
  end
102
58
  end
103
59
  end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "forwardable"
4
+ require_relative "config/inclusion"
5
+
6
+ module Delfos
7
+ class Config
8
+ attr_reader :offline_query_saving, :offline_query_filename
9
+
10
+ attr_accessor :batch_size,
11
+ :call_site_logger,
12
+ :logger,
13
+ :max_query_size
14
+
15
+ extend Forwardable
16
+
17
+ def_delegators :inclusion,
18
+ :included_directories, :included_files, :include=, :include, :include?,
19
+ :excluded_directories, :excluded_files, :exclude=, :exclude, :exclude?
20
+
21
+ def initialize
22
+ @batch_size = default_batch_size
23
+ @logger = default_logger
24
+ @max_query_size = default_max_query_size
25
+ @offline_query_saving = default_offline_query_saving
26
+ @offline_query_filename = nil
27
+ @call_site_logger = default_call_site_logger
28
+ end
29
+
30
+ def offline_query_saving=(bool)
31
+ @offline_query_saving = bool
32
+ @call_site_logger = default_call_site_logger
33
+ end
34
+
35
+ def offline_query_filename=(path)
36
+ @offline_query_filename = path || default_offline_query_filename
37
+ end
38
+
39
+ def neo4j
40
+ setup_neo4j!
41
+ end
42
+
43
+ private
44
+
45
+ def inclusion
46
+ @inclusion ||= Inclusion.new
47
+ end
48
+
49
+ def default_batch_size
50
+ 100
51
+ end
52
+
53
+ def default_call_site_logger
54
+ if @offline_query_saving
55
+ require "delfos/neo4j/offline/call_site_logger"
56
+ Delfos:: Neo4j::Offline::CallSiteLogger.new
57
+ else
58
+ setup_neo4j!
59
+ require "delfos/neo4j/live/call_site_logger"
60
+ Delfos:: Neo4j::Live::CallSiteLogger.new
61
+ end
62
+ end
63
+
64
+ def setup_neo4j!
65
+ require "delfos/neo4j"
66
+ @neo4j ||= Neo4j.config
67
+ end
68
+
69
+ def default_logger
70
+ require "logger"
71
+ Logger.new(STDOUT).tap do |l|
72
+ l.level = Logger::ERROR
73
+ end
74
+ end
75
+
76
+ def default_max_query_size
77
+ 10_000
78
+ end
79
+
80
+ def default_offline_query_saving
81
+ false
82
+ end
83
+
84
+ def default_offline_query_filename
85
+ FileUtils.mkdir_p "./tmp/delfos" if @offline_query_saving
86
+
87
+ "./tmp/delfos/query_parameters.json"
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "delfos/file_system/app_directories"
4
+ require "delfos/file_system/app_files"
5
+
6
+ module Delfos
7
+ class Config
8
+ class Inclusion
9
+ attr_reader :included_directories, :included_files,
10
+ :excluded_directories, :excluded_files
11
+
12
+ def initialize
13
+ require "pathname"
14
+ @included_directories = default_included_directories
15
+ @included_files = []
16
+
17
+ @excluded_directories = []
18
+ @excluded_files = []
19
+ end
20
+
21
+ def exclude(paths)
22
+ append_all_to(paths, "excluded")
23
+ end
24
+
25
+ def include(paths)
26
+ append_all_to(paths, "included")
27
+ end
28
+
29
+ def include=(paths)
30
+ replace_all_with(paths, "included")
31
+ end
32
+
33
+ def exclude=(paths)
34
+ replace_all_with(paths, "excluded")
35
+ end
36
+
37
+ def include?(file)
38
+ app_directories.include?(file) && app_files.include?(file)
39
+ end
40
+
41
+ private
42
+
43
+ def append_all_to(paths, type)
44
+ files, directories = files_and_directories_from(paths)
45
+
46
+ append_to(files, "@#{type}_files")
47
+ append_to(directories, "@#{type}_directories")
48
+ end
49
+
50
+ def append_to(paths, ivar_name)
51
+ ivar = instance_variable_get(ivar_name)
52
+ ivar += paths
53
+ ivar.uniq!
54
+ instance_variable_set(ivar_name, ivar)
55
+ end
56
+
57
+ def replace_all_with(paths, type)
58
+ files, directories = files_and_directories_from(paths)
59
+
60
+ replace_with(files, "@#{type}_files")
61
+ replace_with(directories, "@#{type}_directories")
62
+ end
63
+
64
+ def replace_with(paths, ivar_name)
65
+ instance_variable_set(ivar_name, paths)
66
+ instance_variable_get(ivar_name).uniq!
67
+ end
68
+
69
+ def files_and_directories_from(paths)
70
+ expand_paths(paths).partition(&:file?)
71
+ end
72
+
73
+ def app_directories
74
+ @app_directories ||= FileSystem.app_directories(@included_directories, @excluded_directories)
75
+ end
76
+
77
+ def app_files
78
+ @app_files ||= FileSystem.app_files(@included_files, @excluded_files)
79
+ end
80
+
81
+ def default_included_directories
82
+ %w[app lib].map { |f| Pathname.new(f.to_s).expand_path }
83
+ end
84
+
85
+ def expand_paths(files)
86
+ Array(files).compact.map { |f| Pathname.new(f.to_s).expand_path }
87
+ end
88
+ end
89
+ end
90
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "file_system/distance_calculation"
4
4
  require_relative "file_system/app_directories"
5
+ require_relative "file_system/app_files"
5
6
 
6
7
  module Delfos
7
8
  module FileSystem
@@ -9,8 +10,12 @@ module Delfos
9
10
  DistanceCalculation.new(start_file, finish_file)
10
11
  end
11
12
 
12
- def self.include_file?(file)
13
- FileSystem::AppDirectories.include_file?(file)
13
+ def self.app_directories(included, excluded)
14
+ AppDirectories.new(included, excluded)
15
+ end
16
+
17
+ def self.app_files(included, excluded)
18
+ AppFiles.new(included, excluded)
14
19
  end
15
20
  end
16
21
  end
@@ -1,41 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "common_path"
4
+ require_relative "file_cache"
4
5
 
5
6
  module Delfos
6
7
  module FileSystem
7
- module AppDirectories
8
- extend self
8
+ class AppDirectories
9
+ include FileCache
9
10
 
10
- def exclude_file?(file)
11
- !include_file?(file)
11
+ def initialize(included, excluded)
12
+ @included = included
13
+ @excluded = excluded
12
14
  end
13
15
 
14
- def include_file?(file)
15
- return false if file.nil?
16
- with_cache(file) { should_include?(file) }
16
+ def exclude?(file)
17
+ !include?(file)
17
18
  end
18
19
 
19
- def reset!
20
- @cache = nil
20
+ def include?(file)
21
+ return false if file.nil?
22
+ with_cache(file) { should_include?(file) }
21
23
  end
22
24
 
23
25
  private
24
26
 
25
27
  def should_include?(file)
26
- CommonPath.included_in?(expand_path(file), Delfos.application_directories)
27
- end
28
-
29
- def expand_path(f)
30
- Pathname.new(f).expand_path
28
+ !matches(file, @excluded) && matches(file, @included)
31
29
  end
32
30
 
33
- def with_cache(key)
34
- cache.include?(key) ? cache[key] : cache[key] = yield
31
+ def matches(f, directories)
32
+ CommonPath.included_in?(expand_path(f), directories)
35
33
  end
36
34
 
37
- def cache
38
- @cache ||= {}
35
+ def expand_path(f)
36
+ Pathname.new(f).expand_path
39
37
  end
40
38
  end
41
39
  end