Skip to content

Commit

Permalink
[webui] remove caching for patchinfos - to be moved to API soon
Browse files Browse the repository at this point in the history
  • Loading branch information
coolo committed Nov 8, 2012
1 parent 28cf901 commit 10ba187
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/webui/app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def my_work
@declined_requests = BsRequest.ids(@requests['declined'])
@open_reviews = BsRequest.ids(@requests['reviews'])
@new_requests = BsRequest.ids(@requests['new'])
@open_patchinfos = @displayed_user.running_patchinfos(:cache => false)
@open_patchinfos = @displayed_user.running_patchinfos

session[:requests] = (@requests['declined'] + @requests['reviews'] + @requests['new'])
respond_to do |format|
Expand Down
78 changes: 37 additions & 41 deletions src/webui/app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,51 +90,47 @@ def involved_packages
Collection.find_cached(:id, :what => 'package', :predicate => predicate)
end

def running_patchinfos(opts = {})
cachekey = "#{login}_patchinfos_that_need_work2"
Rails.cache.delete cachekey unless opts[:cache]
return Rails.cache.fetch(cachekey, :expires_in => 10.minutes) do
array = Array.new
col = Collection.find_cached(:id, :what => 'package', :predicate => "[kind='patchinfo' and issue/[@state='OPEN' and owner/@login='#{CGI.escape(login)}']]")
col.each_package do |pi|
hash = { :package => { :project => pi.project, :name => pi.name } }
issues = Array.new

begin
# get users open issues for package
path = "/source/#{URI.escape(pi.project)}/#{URI.escape(pi.name)}?view=issues&states=OPEN&login=#{CGI.escape(login)}"
frontend = ActiveXML::transport
answer = frontend.direct_http URI(path), :method => "GET"
doc = ActiveXML::Node.new(answer)
doc.each("/package/issue") do |s|
i = {}
i[:name]= s.find_first("name").text
i[:tracker]= s.find_first("tracker").text
i[:label]= s.find_first("label").text
i[:url]= s.find_first("url").text
if summary=s.find_first("summary")
i[:summary] = summary.text
end
if state=s.find_first("state")
i[:state] = state.text
end
if login=s.find_first("login")
i[:login] = login.text
end
if updated_at=s.find_first("updated_at")
i[:updated_at] = updated_at.text
end
issues << i
def running_patchinfos
array = Array.new
col = Collection.find_cached(:id, :what => 'package', :predicate => "[kind='patchinfo' and issue/[@state='OPEN' and owner/@login='#{CGI.escape(login)}']]")
col.each_package do |pi|
hash = { :package => { :project => pi.project, :name => pi.name } }
issues = Array.new

begin
# get users open issues for package
path = "/source/#{URI.escape(pi.project)}/#{URI.escape(pi.name)}?view=issues&states=OPEN&login=#{CGI.escape(login)}"
frontend = ActiveXML::transport
answer = frontend.direct_http URI(path), :method => "GET"
doc = ActiveXML::Node.new(answer)
doc.each("/package/issue") do |s|
i = {}
i[:name]= s.find_first("name").text
i[:tracker]= s.find_first("tracker").text
i[:label]= s.find_first("label").text
i[:url]= s.find_first("url").text
if summary=s.find_first("summary")
i[:summary] = summary.text
end

hash[:issues] = issues
array << hash
rescue ActiveXML::Transport::NotFoundError
# Ugly catch for projects that where deleted while this loop is running... bnc#755463)
if state=s.find_first("state")
i[:state] = state.text
end
if login=s.find_first("login")
i[:login] = login.text
end
if updated_at=s.find_first("updated_at")
i[:updated_at] = updated_at.text
end
issues << i
end

hash[:issues] = issues
array << hash
rescue ActiveXML::Transport::NotFoundError
# Ugly catch for projects that where deleted while this loop is running... bnc#755463)
end
return array
end
return array
end

# Returns a tuple (i.e., array) of open requests and open reviews.
Expand Down

0 comments on commit 10ba187

Please sign in to comment.