diff --git a/fixes/fix_commit_comment.rb b/fixes/fix_commit_comment.rb index 94e12f8..5c34745 100755 --- a/fixes/fix_commit_comment.rb +++ b/fixes/fix_commit_comment.rb @@ -42,7 +42,7 @@ def ght end def db - @db ||= ght.get_db + @db ||= ght.db @db end diff --git a/fixes/fix_fake_users.rb b/fixes/fix_fake_users.rb index a36103f..a81010d 100755 --- a/fixes/fix_fake_users.rb +++ b/fixes/fix_fake_users.rb @@ -34,10 +34,10 @@ def settings def run(command) processor = Proc.new do |login| @ght ||= GHTorrent::Mirror.new(settings) - @ght.get_db + @ght.db exists = !api_request("https://api.github.com/users/#{login}").empty? - @ght.get_db[:users].where(:login => login).update(:fake => exists) + @ght.db[:users].where(:login => login).update(:fake => exists) puts "User: #{login}, exists: #{exists}" end diff --git a/fixes/fix_forks.rb b/fixes/fix_forks.rb index 14a756d..1db85ba 100755 --- a/fixes/fix_forks.rb +++ b/fixes/fix_forks.rb @@ -42,7 +42,7 @@ def go if forked[:forked_from].nil? or forked[:forked_from] != parent[:id] tried += 1 - @ght.get_db[:projects].filter(:id => forked[:id]).update(:forked_from => parent[:id]) + @ght.db[:projects].filter(:id => forked[:id]).update(:forked_from => parent[:id]) fixed += 1 puts "Added #{owner}/#{repo} as fork of #{parent_owner}/#{parent_repo}" else diff --git a/fixes/fix_issue_labels.rb b/fixes/fix_issue_labels.rb index 874e43f..78e3554 100755 --- a/fixes/fix_issue_labels.rb +++ b/fixes/fix_issue_labels.rb @@ -34,7 +34,7 @@ def go # logger.debug "Could not get labels for repo #{repo[:login]}/#{repo[:name]}" # end #end - @ght.get_db + @ght.db issues = lbls = 0 col.find({'labels' => {'$ne' => '[]'}}, {:timeout => false}) do |cursor| cursor.each do |issue| diff --git a/fixes/fix_pull_request_comments.rb b/fixes/fix_pull_request_comments.rb index d0c53cc..9416b91 100755 --- a/fixes/fix_pull_request_comments.rb +++ b/fixes/fix_pull_request_comments.rb @@ -23,7 +23,7 @@ def ght end def db - @db ||= ght.get_db + @db ||= ght.db @db end diff --git a/fixes/fix_pull_request_commits.rb b/fixes/fix_pull_request_commits.rb index 7434a7a..d9b9bf3 100755 --- a/fixes/fix_pull_request_commits.rb +++ b/fixes/fix_pull_request_commits.rb @@ -84,7 +84,7 @@ def go end def db - @db ||= ght.get_db + @db ||= ght.db @db end diff --git a/fixes/fix_pull_request_commits_2.rb b/fixes/fix_pull_request_commits_2.rb index 437a0f1..45c65a5 100755 --- a/fixes/fix_pull_request_commits_2.rb +++ b/fixes/fix_pull_request_commits_2.rb @@ -62,7 +62,7 @@ def go end def db - @db ||= ght.get_db + @db ||= ght.db @db end diff --git a/fixes/refresh_pull_request_history.rb b/fixes/refresh_pull_request_history.rb index aba275b..f6513c1 100755 --- a/fixes/refresh_pull_request_history.rb +++ b/fixes/refresh_pull_request_history.rb @@ -63,7 +63,7 @@ def run(command) col.delete_one({'owner' => owner, 'repo' => repo, 'number' => pull_req.to_i}) col.insert_one(retrieved) - @ght.get_db.from(:pull_request_history, :pull_requests, :users, :projects)\ + @ght.db.from(:pull_request_history, :pull_requests, :users, :projects)\ .where(:pull_requests__id => :pull_request_history__pull_request_id)\ .where(:users__id => :projects__owner_id)\ .where(:projects__id => :pull_requests__base_repo_id)\ diff --git a/fixes/update_pullreq_entries_from_events.rb b/fixes/update_pullreq_entries_from_events.rb index 01f104f..94a8734 100755 --- a/fixes/update_pullreq_entries_from_events.rb +++ b/fixes/update_pullreq_entries_from_events.rb @@ -35,7 +35,7 @@ def settings def run(command) processor = Proc.new do |event_id| @ght ||= GHTorrent::Mirror.new(settings) - @ght.get_db + @ght.db pr = persister.find(:events, {'id' => event_id})[0] @@ -46,7 +46,7 @@ def run(command) actor = pr['actor']['login'] created_at = @ght.date(pr['created_at']) - pullreq_entry = @ght.get_db.from(:pull_requests, :projects, :users)\ + pullreq_entry = @ght.db.from(:pull_requests, :projects, :users)\ .where(:users__id => :projects__owner_id)\ .where(:projects__id => :pull_requests__base_repo_id)\ .where(:users__login => owner)\ diff --git a/lib/ghtorrent/commands/full_repo_retriever.rb b/lib/ghtorrent/commands/full_repo_retriever.rb index 82d0f7c..a8ae4f7 100644 --- a/lib/ghtorrent/commands/full_repo_retriever.rb +++ b/lib/ghtorrent/commands/full_repo_retriever.rb @@ -74,8 +74,8 @@ def retrieve_full_repo(owner, repo) # it means that another transaction added/updated the repo. # Just re-running the block should lead to the project being # rejected from further processing due to an updated updated_at field - ght.get_db.transaction(:isolation => :serializable, - :retry_on=>[Sequel::SerializationFailure]) do + ght.db.transaction(:isolation => :serializable, + :retry_on =>[Sequel::SerializationFailure]) do repo_entry = ght.ensure_repo(owner, repo) if repo_entry.nil? @@ -91,7 +91,7 @@ def retrieve_full_repo(owner, repo) return end - ght.get_db.from(:projects).where(:id => repo_entry[:id]).update(:updated_at => Time.now) + ght.db.from(:projects).where(:id => repo_entry[:id]).update(:updated_at => Time.now) end unless options[:no_entities_given] diff --git a/lib/ghtorrent/commands/full_user_retriever.rb b/lib/ghtorrent/commands/full_user_retriever.rb index b9f8fdd..9f0bab5 100644 --- a/lib/ghtorrent/commands/full_user_retriever.rb +++ b/lib/ghtorrent/commands/full_user_retriever.rb @@ -40,7 +40,7 @@ def retrieve_user(login) exit else ght.transaction do - ght.get_db.from(:users).where(:login => login).update(:users__deleted => true) + ght.db.from(:users).where(:login => login).update(:users__deleted => true) end warn "User #{login} marked as deleted" return @@ -60,7 +60,7 @@ def retrieve_user(login) # Update geo location information geo = geolocate(on_github['location']) - ght.get_db.from(:users).where(:login => login).update( + ght.db.from(:users).where(:login => login).update( # Geolocation info :users__long => geo['long'].to_f, :users__lat => geo['lat'].to_f, diff --git a/lib/ghtorrent/commands/repo_updater.rb b/lib/ghtorrent/commands/repo_updater.rb index b41dafb..7c54b2c 100644 --- a/lib/ghtorrent/commands/repo_updater.rb +++ b/lib/ghtorrent/commands/repo_updater.rb @@ -15,7 +15,7 @@ def persister end def db - @db ||= ght.get_db + ght.db end def ght diff --git a/lib/ghtorrent/event_processing.rb b/lib/ghtorrent/event_processing.rb index 395050c..6e59c9b 100644 --- a/lib/ghtorrent/event_processing.rb +++ b/lib/ghtorrent/event_processing.rb @@ -42,7 +42,7 @@ def MemberEvent(data) date_added = data['created_at'] ght.transaction do - pr_members = ght.get_db[:project_members] + pr_members = ght.db[:project_members] project = ght.ensure_repo(owner, repo) new_user = ght.ensure_user(new_member, false, false) diff --git a/lib/ghtorrent/ghtorrent.rb b/lib/ghtorrent/ghtorrent.rb index e97cd03..b863445 100644 --- a/lib/ghtorrent/ghtorrent.rb +++ b/lib/ghtorrent/ghtorrent.rb @@ -33,7 +33,7 @@ def dispose end # Get a connection to the database - def get_db + def db return @db unless @db.nil? Sequel.single_threaded = true @@ -116,8 +116,8 @@ def ensure_commits(user, repo, sha = nil, return_retrieved = false) # Get the parents for a specific commit. The commit must be first stored # in the database. def ensure_parents(commit) - commits = @db[:commits] - parents = @db[:commit_parents] + commits = db[:commits] + parents = db[:commit_parents] commit['parents'].map do |p| save do url = p['url'].split(/\//) @@ -166,17 +166,17 @@ def ensure_repo_commit(user, repo, sha) return end - commitid = @db[:commits].first(:sha => sha)[:id] + commitid = db[:commits].first(:sha => sha)[:id] - exists = @db[:project_commits].first(:project_id => project[:id], + exists = db[:project_commits].first(:project_id => project[:id], :commit_id => commitid) if exists.nil? - @db[:project_commits].insert( + db[:project_commits].insert( :project_id => project[:id], :commit_id => commitid ) info "Added commit_assoc of #{sha} with #{user}/#{repo}" - @db[:project_commits].first(:project_id => project[:id], + db[:project_commits].first(:project_id => project[:id], :commit_id => commitid) else debug "Association of commit #{sha} with repo #{user}/#{repo} exists" @@ -196,7 +196,7 @@ def ensure_repo_commit(user, repo, sha) # The (added/modified) user entry as a Hash. def commit_user(githubuser, commituser) - users = @db[:users] + users = db[:users] name = commituser['name'] email = commituser['email'] #if is_valid_email(commituser['email']) @@ -306,7 +306,7 @@ def ensure_user(user, followers = true, orgs = true) # If the user can be retrieved, it is returned as a Hash. Otherwise, # the result is nil def ensure_user_byuname(user) - users = @db[:users] + users = db[:users] usr = users.first(:login => user) if usr.nil? @@ -364,7 +364,7 @@ def ensure_user_byuname(user) # [user] The user login to find followers by def ensure_user_followers(followed) curuser = ensure_user(followed, false, false) - followers = @db.from(:followers, :users).\ + followers = db.from(:followers, :users).\ where(:followers__follower_id => :users__id). where(:followers__user_id => curuser[:id]).select(:login).all @@ -388,7 +388,7 @@ def ensure_user_follower(followed, follower, date_added = nil) return end - followers = @db[:followers] + followers = db[:followers] follower_id = follower_user[:id] followed_id = followed_user[:id] @@ -426,7 +426,7 @@ def ensure_user_follower(followed, follower, date_added = nil) def ensure_user_following(user) curuser = ensure_user(user, false, false) - following = @db.from(:followers, :users).\ + following = db.from(:followers, :users).\ where(:followers__follower_id => curuser[:id]).\ where(:followers__user_id => :users__id).select(:login).all @@ -450,7 +450,7 @@ def ensure_user_following(user) # If the user can be retrieved, it is returned as a Hash. Otherwise, # the result is nil def ensure_user_byemail(email, name) - users = @db[:users] + users = db[:users] usr = users.first(:email => email) if usr.nil? @@ -519,7 +519,7 @@ def ensure_user_byemail(email, name) # the result is nil def ensure_repo(user, repo, recursive = false) - repos = @db[:projects] + repos = db[:projects] curuser = ensure_user(user, false, false) if curuser.nil? @@ -605,7 +605,7 @@ def ensure_languages(owner, repo) ts = Time.now langs.keys.each do |lang| - @db[:project_languages].insert( + db[:project_languages].insert( :project_id => currepo[:id], :language => lang.downcase, :bytes => langs[lang], @@ -613,7 +613,7 @@ def ensure_languages(owner, repo) ) info "Added project_language #{owner}/#{repo} -> #{lang} (#{langs[lang]} bytes)" end - @db[:project_languages].where(:project_id => currepo[:id]).where(:created_at => ts).all + db[:project_languages].where(:project_id => currepo[:id]).where(:created_at => ts).all end # Fast path to project forking. Retrieve all commits page by page @@ -670,7 +670,7 @@ def ensure_fork_commits(owner, repo, parent_owner, parent_repo) for c in commits processed += 1 exists_in_parent = - !@db.from(:project_commits, :commits).\ + !db.from(:project_commits, :commits).\ where(:project_commits__commit_id => :commits__id).\ where(:project_commits__project_id => parent[:id]).\ where(:commits__sha => c['sha']).first.nil? @@ -692,9 +692,9 @@ def ensure_fork_commits(owner, repo, parent_owner, parent_repo) end if found - shared_commit = @db[:commits].first(:sha => sha) + shared_commit = db[:commits].first(:sha => sha) copied = 0 - @db.from(:project_commits, :commits).\ + db.from(:project_commits, :commits).\ where(:project_commits__commit_id => :commits__id).\ where(:project_commits__project_id => parent[:id]).\ where('commits.created_at < ?', shared_commit[:created_at]).\ @@ -702,7 +702,7 @@ def ensure_fork_commits(owner, repo, parent_owner, parent_repo) each do |c| copied += 1 begin - @db[:project_commits].insert( + db[:project_commits].insert( :project_id => currepo[:id], :commit_id => c[:id] ) @@ -723,7 +723,7 @@ def ensure_project_members(user, repo, refresh = false) currepo = ensure_repo(user, repo) time = currepo[:created_at] - project_members = @db.from(:project_members, :users).\ + project_members = db.from(:project_members, :users).\ where(:project_members__user_id => :users__id).\ where(:project_members__repo_id => currepo[:id]).select(:login).all @@ -739,7 +739,7 @@ def ensure_project_members(user, repo, refresh = false) ## # Make sure that a project member exists in a project def ensure_project_member(owner, repo, new_member, date_added) - pr_members = @db[:project_members] + pr_members = db[:project_members] project = ensure_repo(owner, repo) new_user = ensure_user(new_member, false, false) @@ -810,7 +810,7 @@ def ensure_participation(user, organization, members = true) usr = ensure_user(user, false, false) - org_members = @db[:organization_members] + org_members = db[:organization_members] participates = org_members.first(:user_id => usr[:id], :org_id => org[:id]) if participates.nil? @@ -832,7 +832,7 @@ def ensure_participation(user, organization, members = true) # [organization] The login name of the organization # def ensure_org(organization, members = true) - org = @db[:users].first(:login => organization, :type => 'org') + org = db[:users].first(:login => organization, :type => 'org') if org.nil? org = ensure_user(organization, false, false) @@ -860,8 +860,8 @@ def ensure_org(organization, members = true) # [user] The repository containing the commit whose comments will be retrieved # [sha] The commit sha to retrieve comments for def ensure_commit_comments(user, repo, sha) - commit_id = @db[:commits].first(:sha => sha)[:id] - stored_comments = @db[:commit_comments].filter(:commit_id => commit_id) + commit_id = db[:commits].first(:sha => sha)[:id] + stored_comments = db[:commit_comments].filter(:commit_id => commit_id) commit_comments = retrieve_commit_comments(user, repo, sha) not_saved = commit_comments.reduce([]) do |acc, x| @@ -877,7 +877,7 @@ def ensure_commit_comments(user, repo, sha) def ensure_commit_comment(owner, repo, sha, comment_id) - stored_comment = @db[:commit_comments].first(:comment_id => comment_id) + stored_comment = db[:commit_comments].first(:comment_id => comment_id) if stored_comment.nil? retrieved = retrieve_commit_comment(owner, repo, sha, comment_id) @@ -889,7 +889,7 @@ def ensure_commit_comment(owner, repo, sha, comment_id) commit = ensure_commit(repo, sha, owner, false) user = ensure_user(retrieved['user']['login'], false, false) - @db[:commit_comments].insert( + db[:commit_comments].insert( :commit_id => commit[:id], :user_id => user[:id], :body => retrieved['body'][0..255], @@ -902,7 +902,7 @@ def ensure_commit_comment(owner, repo, sha, comment_id) else debug "Commit comment #{sha} -> #{comment_id} exists" end - @db[:commit_comments].first(:comment_id => comment_id) + db[:commit_comments].first(:comment_id => comment_id) end ## @@ -915,7 +915,7 @@ def ensure_watchers(owner, repo, refresh = false) return end - watchers = @db.from(:watchers, :users).\ + watchers = db.from(:watchers, :users).\ where(:watchers__user_id => :users__id).\ where(:watchers__repo_id => currepo[:id]).select(:login).all @@ -991,7 +991,7 @@ def ensure_pull_requests(owner, repo, refresh = false) raw_pull_reqs = if refresh retrieve_pull_requests(owner, repo, refresh = true) else - pull_reqs = @db[:pull_requests].filter(:base_repo_id => currepo[:id]).all + pull_reqs = db[:pull_requests].filter(:base_repo_id => currepo[:id]).all retrieve_pull_requests(owner, repo).reduce([]) do |acc, x| if pull_reqs.find { |y| y[:pullreq_id] == x['number'] }.nil? acc << x @@ -1009,7 +1009,7 @@ def ensure_pull_request_history(id, ts, act, actor) user = unless actor.nil? ensure_user(actor, false, false) end - pull_req_history = @db[:pull_request_history] + pull_req_history = db[:pull_request_history] entry = if ['opened', 'merged'].include? act pull_req_history.first(:pull_request_id => id, @@ -1044,7 +1044,7 @@ def ensure_pull_request_history(id, ts, act, actor) def ensure_pull_request(owner, repo, pullreq_id, comments = true, commits = true, history = true, state = nil, actor = nil, created_at = nil) - pulls_reqs = @db[:pull_requests] + pulls_reqs = db[:pull_requests] project = ensure_repo(owner, repo) @@ -1145,7 +1145,7 @@ def log_msg(req) # Add a fake (or not so fake) issue in the issues table to serve # as root for retrieving discussion comments for this pull request - issues = @db[:issues] + issues = db[:issues] issue = issues.first(:pull_request_id => pull_req[:id]) if issue.nil? @@ -1200,7 +1200,7 @@ def ensure_pullreq_comments(owner, repo, pullreq_id) retrieve_pull_req_comments(owner, repo, pullreq_id).reduce([]) do |acc, x| - if @db[:pull_request_comments].first(:pull_request_id => pull_req[:id], + if db[:pull_request_comments].first(:pull_request_id => pull_req[:id], :comment_id => x['id']).nil? acc << x else @@ -1223,7 +1223,7 @@ def ensure_pullreq_comment(owner, repo, pullreq_id, comment_id) return end - exists = @db[:pull_request_comments].first(:pull_request_id => pull_req[:id], + exists = db[:pull_request_comments].first(:pull_request_id => pull_req[:id], :comment_id => comment_id) if exists.nil? @@ -1243,7 +1243,7 @@ def ensure_pullreq_comment(owner, repo, pullreq_id, comment_id) commit = ensure_commit(repo, retrieved['original_commit_id'],owner) - @db[:pull_request_comments].insert( + db[:pull_request_comments].insert( :pull_request_id => pull_req[:id], :user_id => commenter[:id], :comment_id => comment_id, @@ -1253,7 +1253,7 @@ def ensure_pullreq_comment(owner, repo, pullreq_id, comment_id) :created_at => date(retrieved['created_at']) ) info "Added pullreq_comment #{comment_id} for #{owner}/#{repo} -> #{pullreq_id}" - @db[:pull_request_comments].first(:pull_request_id => pull_req[:id], + db[:pull_request_comments].first(:pull_request_id => pull_req[:id], :comment_id => comment_id) else debug "Comment #{comment_id} for pullreq #{owner}/#{repo} -> #{pullreq_id} exists" @@ -1278,10 +1278,10 @@ def ensure_pull_request_commits(owner, repo, pullreq_id) acc }.map do |c| save do - exists = @db[:pull_request_commits].first(:pull_request_id => pullreq[:id], + exists = db[:pull_request_commits].first(:pull_request_id => pullreq[:id], :commit_id => c[:id]) if exists.nil? - @db[:pull_request_commits].insert(:pull_request_id => pullreq[:id], + db[:pull_request_commits].insert(:pull_request_id => pullreq[:id], :commit_id => c[:id]) info "Added pullreq_commit #{c[:sha]} to #{owner}/#{repo} -> #{pullreq_id}" @@ -1307,7 +1307,7 @@ def ensure_forks(owner, repo) return end - existing_forks = @db.from(:projects, :users).\ + existing_forks = db.from(:projects, :users).\ where(:users__id => :projects__owner_id). \ where(:projects__forked_from => currepo[:id]).select(:projects__name, :login).all @@ -1359,7 +1359,7 @@ def ensure_issues(owner, repo, refresh = false) raw_issues = if refresh retrieve_issues(owner, repo, refresh = true) else - issues = @db[:issues].filter(:repo_id => currepo[:id]).all + issues = db[:issues].filter(:repo_id => currepo[:id]).all retrieve_issues(owner, repo).reduce([]) do |acc, x| if issues.find { |y| y[:issue_id] == x['number'] }.nil? acc << x @@ -1377,7 +1377,7 @@ def ensure_issues(owner, repo, refresh = false) def ensure_issue(owner, repo, issue_id, events = true, comments = true, labels = true) - issues = @db[:issues] + issues = db[:issues] repository = ensure_repo(owner, repo) if repo.nil? @@ -1452,7 +1452,7 @@ def ensure_issue_events(owner, repo, issue_id) retrieve_issue_events(owner, repo, issue_id).reduce([]) do |acc, x| - if @db[:issue_events].first(:issue_id => issue[:id], + if db[:issue_events].first(:issue_id => issue[:id], :event_id => x['id']).nil? acc << x else @@ -1475,7 +1475,7 @@ def ensure_issue_event(owner, repo, issue_id, event_id) issue_event_str = "#{owner}/#{repo} -> #{issue_id}/#{event_id}" - curevent = @db[:issue_events].first(:issue_id => issue[:id], + curevent = db[:issue_events].first(:issue_id => issue[:id], :event_id => event_id) if curevent.nil? @@ -1501,14 +1501,14 @@ def ensure_issue_event(owner, repo, issue_id, event_id) if retrieved['event'] == 'assigned' def update_assignee(owner, repo, issue, actor) - @db[:issues].first(:id => issue[:id]).update(:assignee_id => actor[:id]) + db[:issues].first(:id => issue[:id]).update(:assignee_id => actor[:id]) info "Updated #{owner}/#{repo} -> #{issue[:id]}, assignee -> #{actor[:id]}" end if issue[:assignee_id].nil? then update_assignee(owner, repo, issue, actor) else - existing = @db[:issue_events].\ + existing = db[:issue_events].\ filter(:issue_id => issue[:id],:action => 'assigned').\ order(Sequel.desc(:created_at)).first if existing.nil? @@ -1519,7 +1519,7 @@ def update_assignee(owner, repo, issue, actor) end end - @db[:issue_events].insert( + db[:issue_events].insert( :event_id => event_id, :issue_id => issue[:id], :actor_id => unless actor.nil? then actor[:id] end, @@ -1528,7 +1528,7 @@ def update_assignee(owner, repo, issue, actor) :created_at => date(retrieved['created_at'])) info "Added issue_event #{owner}/#{repo} -> #{issue_id}/#{issue_event_str}" - @db[:issue_events].first(:issue_id => issue[:id], + db[:issue_events].first(:issue_id => issue[:id], :event_id => event_id) else debug "Issue event #{owner}/#{repo} -> #{issue_id}/#{issue_event_str} exists" @@ -1552,7 +1552,7 @@ def ensure_issue_comments(owner, repo, issue_id, pull_req_id = nil) issue = if pull_req_id.nil? ensure_issue(owner, repo, issue_id, false, false, false) else - @db[:issues].first(:pull_request_id => pull_req_id) + db[:issues].first(:pull_request_id => pull_req_id) end if issue.nil? @@ -1562,7 +1562,7 @@ def ensure_issue_comments(owner, repo, issue_id, pull_req_id = nil) retrieve_issue_comments(owner, repo, issue_id).reduce([]) do |acc, x| - if @db[:issue_comments].first(:issue_id => issue[:id], + if db[:issue_comments].first(:issue_id => issue[:id], :comment_id => x['id']).nil? acc << x else @@ -1580,7 +1580,7 @@ def ensure_issue_comment(owner, repo, issue_id, comment_id, issue = if pull_req_id.nil? ensure_issue(owner, repo, issue_id, false, false, false) else - @db[:issues].first(:pull_request_id => pull_req_id) + db[:issues].first(:pull_request_id => pull_req_id) end if issue.nil? @@ -1590,7 +1590,7 @@ def ensure_issue_comment(owner, repo, issue_id, comment_id, issue_comment_str = "#{owner}/#{repo} -> #{issue_id}/#{comment_id}" - curcomment = @db[:issue_comments].first(:issue_id => issue[:id], + curcomment = db[:issue_comments].first(:issue_id => issue[:id], :comment_id => comment_id) if curcomment.nil? @@ -1603,7 +1603,7 @@ def ensure_issue_comment(owner, repo, issue_id, comment_id, user = ensure_user(retrieved['user']['login'], false, false) - @db[:issue_comments].insert( + db[:issue_comments].insert( :comment_id => comment_id, :issue_id => issue[:id], :user_id => unless user.nil? then user[:id] end, @@ -1611,7 +1611,7 @@ def ensure_issue_comment(owner, repo, issue_id, comment_id, ) info "Added issue_comment #{issue_comment_str}" - @db[:issue_comments].first(:issue_id => issue[:id], + db[:issue_comments].first(:issue_id => issue[:id], :comment_id => comment_id) else debug "Issue comment #{issue_comment_str} exists" @@ -1629,7 +1629,7 @@ def ensure_labels(owner, repo, refresh = false) return end - repo_labels = @db[:repo_labels].filter(:repo_id => currepo[:id]).all + repo_labels = db[:repo_labels].filter(:repo_id => currepo[:id]).all retrieve_repo_labels(owner, repo, refresh).reduce([]) do |acc, x| if repo_labels.find {|y| y[:name] == x['name']}.nil? @@ -1650,7 +1650,7 @@ def ensure_repo_label(owner, repo, name) return end - label = @db[:repo_labels].first(:repo_id => currepo[:id], :name => name) + label = db[:repo_labels].first(:repo_id => currepo[:id], :name => name) if label.nil? retrieved = retrieve_repo_label(owner, repo, name) @@ -1660,13 +1660,13 @@ def ensure_repo_label(owner, repo, name) return end - @db[:repo_labels].insert( + db[:repo_labels].insert( :repo_id => currepo[:id], :name => name ) info "Added repo_label #{owner}/#{repo} -> #{name}" - @db[:repo_labels].first(:repo_id => currepo[:id], :name => name) + db[:repo_labels].first(:repo_id => currepo[:id], :name => name) else label end @@ -1683,7 +1683,7 @@ def ensure_issue_labels(owner, repo, issue_id) return end - issue_labels = @db.from(:issue_labels, :repo_labels)\ + issue_labels = db.from(:issue_labels, :repo_labels)\ .where(:issue_labels__label_id => :repo_labels__id)\ .where(:issue_labels__issue_id => issue[:id])\ .select(:repo_labels__name).all @@ -1716,17 +1716,17 @@ def ensure_issue_label(owner, repo, issue_id, name) return end - issue_lbl = @db[:issue_labels].first(:label_id => label[:id], + issue_lbl = db[:issue_labels].first(:label_id => label[:id], :issue_id => issue[:id]) if issue_lbl.nil? - @db[:issue_labels].insert( + db[:issue_labels].insert( :label_id => label[:id], :issue_id => issue[:id], ) info "Added issue_label #{name} to issue #{owner}/#{repo} -> #{issue_id}" - @db[:issue_labels].first(:label_id => label[:id], + db[:issue_labels].first(:label_id => label[:id], :issue_id => issue[:id]) else debug "Issue label #{name} to issue #{owner}/#{repo} -> #{issue_id} exists" @@ -1738,13 +1738,13 @@ def ensure_issue_label(owner, repo, issue_id, name) # Run a block in a DB transaction. Exceptions trigger transaction rollback # and are rethrown. def transaction(&block) - @db ||= get_db - @persister ||= persister + db + persister result = nil start_time = Time.now begin - @db.transaction(:rollback => :reraise, :isolation => :repeatable, + db.transaction(:rollback => :reraise, :isolation => :repeatable, :retry_on => @retry_on_error, :num_retries => 3) do result = yield block end @@ -1776,7 +1776,7 @@ def save(&block) # Store a commit contained in a hash. First check whether the commit exists. def store_commit(c, repo, user) - commits = @db[:commits] + commits = db[:commits] commit = commits.first(:sha => c['sha']) if commit.nil? diff --git a/lib/ghtorrent/transacted_gh_torrent.rb b/lib/ghtorrent/transacted_gh_torrent.rb index 6e2de07..055a077 100644 --- a/lib/ghtorrent/transacted_gh_torrent.rb +++ b/lib/ghtorrent/transacted_gh_torrent.rb @@ -110,7 +110,7 @@ def ensure_org(user, members = true) end def check_transaction(&block) - if get_db.in_transaction? + if db.in_transaction? yield block else transaction do