Commit 7636aed4 authored by Samir Noir's avatar Samir Noir 🧀
Browse files

Better performance for resources' versions listing

parent 7f7e15a0
Pipeline #305308 passed with stages
in 17 minutes and 48 seconds
......@@ -188,7 +188,11 @@ class VersionsController < ApplicationController
protected
def resource_path
@resource_path ||= params[:resource].gsub(%r{/?platforms}, '')
if params[:resource]
@resource_path ||= params[:resource].gsub(%r{/?platforms}, '')
else
''
end
end
def metadata_for_commit(commit, resource_path)
......
......@@ -302,17 +302,10 @@ module Grid5000
if oid
walker = Rugged::Walker.new(instance)
walker.sorting(Rugged::SORT_DATE)
walker.push(oid)
commits = walker.select do |commit|
commit.diff(paths: [path]).size > 0
end
if commits.empty?
commits = walker.select do |commit|
commit.diff(paths: [path + '.json']).size > 0
end
entry_changed?(commit, path)
end
end
......@@ -322,6 +315,39 @@ module Grid5000
'items' => commits.slice(offset, limit)
}
end
# Adapted from: https://github.com/libgit2/rugged/issues/343
def entry_changed?(commit, path)
parent = commit.parents[0]
entry = commit.tree.path(path) rescue nil
# if at a root commit, consider it changed if we have this file;
# i.e. if we added it in the initial commit
if !parent
return entry != nil
end
parent_entry = begin
parent.tree.path(path)
rescue Rugged::TreeError
begin
parent.tree.path(path + '.json')
rescue Rugged::TreeError
false
end
end
# does exist in either, no change
if !entry && !parent_entry
false
# only in one of them, change
elsif !entry || !parent_entry
true
# otherwise it's changed if their ids arent' the same
else
entry[:oid] != parent_entry[:oid]
end
end
end
module Errors
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment