Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
grid5000
g5k-api
Commits
7636aed4
Commit
7636aed4
authored
Sep 27, 2021
by
Samir Noir
🧀
Browse files
Better performance for resources' versions listing
parent
7f7e15a0
Pipeline
#305308
passed with stages
in 17 minutes and 48 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
app/controllers/versions_controller.rb
View file @
7636aed4
...
@@ -188,7 +188,11 @@ class VersionsController < ApplicationController
...
@@ -188,7 +188,11 @@ class VersionsController < ApplicationController
protected
protected
def
resource_path
def
resource_path
if
params
[
:resource
]
@resource_path
||=
params
[
:resource
].
gsub
(
%r{/?platforms}
,
''
)
@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
)
...
...
lib/grid5000/repository.rb
View file @
7636aed4
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment