Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leverage a lookup table when building dependencies to improve performance #126 #127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions lib/gush/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,27 @@ def resolve_dependencies
end
end

def find_job(name)
match_data = /(?<klass>\w*[^-])-(?<identifier>.*)/.match(name.to_s)
def build_job_lookup
@job_lookup = {
klass: jobs.each_with_object({}) { |job, lookup| lookup[job.klass.to_s] = job },
name: jobs.each_with_object({}) { |job, lookup| lookup[job.name.to_s] = job }
}
end

def find_job(identifier)
# Build the lookup table if it doesn't exist
build_job_lookup unless @job_lookup

# Use regex to determine which lookup to use
match_data = /(?<klass>\w*[^-])-(?<identifier>.*)/.match(identifier.to_s)

if match_data.nil?
job = jobs.find { |node| node.klass.to_s == name.to_s }
# Lookup by klass if the pattern doesn't match
@job_lookup[:klass][identifier.to_s]
else
job = jobs.find { |node| node.name.to_s == name.to_s }
# Lookup by name if the pattern matches
@job_lookup[:name][identifier.to_s]
end

job
end

def finished?
Expand Down Expand Up @@ -146,6 +157,7 @@ def reload

self.jobs = flow.jobs
self.stopped = flow.stopped
@job_lookup = nil

self
end
Expand Down