Attention une mise à jour du service Gitlab va être effectuée le mardi 18 janvier (et non lundi 17 comme annoncé précédemment) entre 18h00 et 18h30. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes.

Commit e1ad4b88 authored by Samir Noir's avatar Samir Noir 🧀
Browse files

Better performance for resources' versions listing

parent b75c9076
Pipeline #305362 passed with stages
in 18 minutes and 25 seconds
...@@ -188,7 +188,11 @@ class VersionsController < ApplicationController ...@@ -188,7 +188,11 @@ class VersionsController < ApplicationController
protected protected
def resource_path def resource_path
@resource_path ||= params[:resource].gsub(%r{/?platforms}, '') if params[:resource]
@resource_path ||= params[:resource].gsub(%r{/?platforms}, '')
else
''
end
end end
def metadata_for_commit(commit, resource_path) def metadata_for_commit(commit, resource_path)
......
...@@ -302,17 +302,10 @@ module Grid5000 ...@@ -302,17 +302,10 @@ module Grid5000
if oid if oid
walker = Rugged::Walker.new(instance) walker = Rugged::Walker.new(instance)
walker.sorting(Rugged::SORT_DATE)
walker.push(oid) walker.push(oid)
commits = walker.select do |commit| commits = walker.select do |commit|
commit.diff(paths: [path]).size > 0 entry_changed?(commit, path)
end
if commits.empty?
commits = walker.select do |commit|
commit.diff(paths: [path + '.json']).size > 0
end
end end
end end
...@@ -322,6 +315,39 @@ module Grid5000 ...@@ -322,6 +315,39 @@ module Grid5000
'items' => commits.slice(offset, limit) 'items' => commits.slice(offset, limit)
} }
end 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 end
module Errors 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