Skip to content

Commit

Permalink
[api] use efficient way to fetch issues after apibugzilla.novell.com …
Browse files Browse the repository at this point in the history
…is doing the right thing :)
  • Loading branch information
adrianschroeter committed Jan 20, 2012
1 parent d649625 commit fe7344f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 31 deletions.
55 changes: 24 additions & 31 deletions src/api/app/models/issue_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@ def issue(issue_id)
end

def update_issues()
# before asking remote to ensure that it is older then on remote, assuming ntp works ...
# to be sure, just reduce it by 5 seconds (would be nice to have a counter at bugzilla to
# guarantee a complete search)
update_time_stamp = Time.at(Time.now.to_f - 5)

result = bugzilla_server.search(:last_change_time => self.issues_updated)
ids = result["bugs"].map{ |x| x.r["id"].to_s }

ret = private_fetch_issues(ids)

Expand All @@ -103,44 +107,33 @@ def fetch_issues(issues=nil)
end

private
def private_fetch_issues(ids=nil)
def private_fetch_issues(ids)
unless self.enable_fetch
logger.info "Bug mentioned on #{self.name}, but fetching from server is disabled"
return
end

# before asking remote to ensure that it is older then on remote, assuming ntp works ...
# to be sure, just reduce it by 5 seconds (would be nice to have a counter at bugzilla to
# guarantee a complete search)
update_time_stamp = Time.at(Time.now.to_f - 5)
update_time_stamp = Time.at(Time.now.to_f)

if kind == "bugzilla"
# the efficient way, but bugzilla just errors out usually with it:
# result = bugzilla_server.get(:ids => ids }, :permissive => true)
# So creating more load here for bugzilla
ids.each do |i|
# do not ask for missing entries
next unless Issue.find_by_name_and_tracker i.to_s, self.name

begin
result = bugzilla_server.get(:ids => [i])
result["bugs"].each{ |r|
issue = Issue.find_by_name_and_tracker r["id"].to_s, self.name
if issue
issue.state = Issue.bugzilla_state(r["status"])
u = User.find_by_email(r["assigned_to"].to_s)
logger.info "Bug user #{r["assigned_to"].to_s} is not found in OBS user database" unless u
issue.owner_id = u.id if u
issue.updated_at = update_time_stamp
issue.description = r["summary"] # FIXME2.3 check for internal only bugs here
issue.save
end
}
rescue RuntimeError => e
logger.error "Unable to fetch issue #{e.inspect}"
rescue XMLRPC::FaultException => e
logger.error "Error: #{e.faultCode} #{e.faultString}"
end
begin
result = bugzilla_server.get(:ids => [ids], :permissive => 1)
result["bugs"].each{ |r|
issue = Issue.find_by_name_and_tracker r["id"].to_s, self.name
if issue
issue.state = Issue.bugzilla_state(r["status"])
u = User.find_by_email(r["assigned_to"].to_s)
logger.info "Bug user #{r["assigned_to"].to_s} is not found in OBS user database" unless u
issue.owner_id = u.id if u
issue.updated_at = update_time_stamp
issue.description = r["summary"] # FIXME2.3 check for internal only bugs here
issue.save
end
}
rescue RuntimeError => e
logger.error "Unable to fetch issue #{e.inspect}"
rescue XMLRPC::FaultException => e
logger.error "Error: #{e.faultCode} #{e.faultString}"
end
elsif kind == "fate"
# Try with 'IssueTracker.find_by_name('fate').details('123')' on script/console
Expand Down
2 changes: 2 additions & 0 deletions src/api/db/development_structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,8 @@ INSERT INTO schema_migrations (version) VALUES ('20120119204301');

INSERT INTO schema_migrations (version) VALUES ('20120120104301');

INSERT INTO schema_migrations (version) VALUES ('20120120114301');

INSERT INTO schema_migrations (version) VALUES ('21');

INSERT INTO schema_migrations (version) VALUES ('22');
Expand Down

0 comments on commit fe7344f

Please sign in to comment.