Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
69bcef32
Commit
69bcef32
authored
Oct 08, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'public/trending-projects-performance'
parents
a2374758
4841e883
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
141 additions
and
9 deletions
+141
-9
CHANGELOG
CHANGELOG
+1
-0
app/finders/trending_projects_finder.rb
app/finders/trending_projects_finder.rb
+2
-9
app/models/project.rb
app/models/project.rb
+14
-0
spec/benchmarks/finders/trending_projects_finder_spec.rb
spec/benchmarks/finders/trending_projects_finder_spec.rb
+14
-0
spec/benchmarks/models/project_spec.rb
spec/benchmarks/models/project_spec.rb
+33
-0
spec/finders/trending_projects_finder_spec.rb
spec/finders/trending_projects_finder_spec.rb
+39
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+38
-0
No files found.
CHANGELOG
View file @
69bcef32
...
@@ -4,6 +4,7 @@ v 8.1.0 (unreleased)
...
@@ -4,6 +4,7 @@ v 8.1.0 (unreleased)
- Add support for creating directories from Files page (Stan Hu)
- Add support for creating directories from Files page (Stan Hu)
- Allow removing of project without confirmation when JavaScript is disabled (Stan Hu)
- Allow removing of project without confirmation when JavaScript is disabled (Stan Hu)
- Support filtering by "Any" milestone or issue and fix "No Milestone" and "No Label" filters (Stan Hu)
- Support filtering by "Any" milestone or issue and fix "No Milestone" and "No Label" filters (Stan Hu)
- Improved performance of the trending projects page
- Fix bug where transferring a project would result in stale commit links (Stan Hu)
- Fix bug where transferring a project would result in stale commit links (Stan Hu)
- Include full path of source and target branch names in New Merge Request page (Stan Hu)
- Include full path of source and target branch names in New Merge Request page (Stan Hu)
- Add user preference to view activities as default dashboard (Stan Hu)
- Add user preference to view activities as default dashboard (Stan Hu)
...
...
app/finders/trending_projects_finder.rb
View file @
69bcef32
class
TrendingProjectsFinder
class
TrendingProjectsFinder
def
execute
(
current_user
,
start_date
=
nil
)
def
execute
(
current_user
,
start_date
=
1
.
month
.
ago
)
start_date
||=
Date
.
today
-
1
.
month
projects_for
(
current_user
).
trending
(
start_date
)
projects
=
projects_for
(
current_user
)
# Determine trending projects based on comments count
# for period of time - ex. month
projects
.
joins
(
:notes
).
where
(
'notes.created_at > ?'
,
start_date
).
group
(
"projects.id"
).
reorder
(
"count(notes.id) DESC"
)
end
end
private
private
...
...
app/models/project.rb
View file @
69bcef32
...
@@ -260,6 +260,20 @@ class Project < ActiveRecord::Base
...
@@ -260,6 +260,20 @@ class Project < ActiveRecord::Base
name_pattern
=
Gitlab
::
Regex
::
NAMESPACE_REGEX_STR
name_pattern
=
Gitlab
::
Regex
::
NAMESPACE_REGEX_STR
%r{(?<project>
#{
name_pattern
}
/
#{
name_pattern
}
)}
%r{(?<project>
#{
name_pattern
}
/
#{
name_pattern
}
)}
end
end
def
trending
(
since
=
1
.
month
.
ago
)
# By counting in the JOIN we don't expose the GROUP BY to the outer query.
# This means that calls such as "any?" and "count" just return a number of
# the total count, instead of the counts grouped per project as a Hash.
join_body
=
"INNER JOIN (
SELECT project_id, COUNT(*) AS amount
FROM notes
WHERE created_at >=
#{
sanitize
(
since
)
}
GROUP BY project_id
) join_note_counts ON projects.id = join_note_counts.project_id"
joins
(
join_body
).
reorder
(
'join_note_counts.amount DESC'
)
end
end
end
def
team
def
team
...
...
spec/benchmarks/finders/trending_projects_finder_spec.rb
0 → 100644
View file @
69bcef32
require
'spec_helper'
describe
TrendingProjectsFinder
,
benchmark:
true
do
describe
'#execute'
do
let
(
:finder
)
{
described_class
.
new
}
let
(
:user
)
{
create
(
:user
)
}
# to_a is used to force actually running the query (instead of just building
# it).
benchmark_subject
{
finder
.
execute
(
user
).
non_archived
.
to_a
}
it
{
is_expected
.
to
iterate_per_second
(
500
)
}
end
end
spec/benchmarks/models/project_spec.rb
0 → 100644
View file @
69bcef32
require
'spec_helper'
describe
Project
,
benchmark:
true
do
describe
'.trending'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:project1
)
{
create
(
:empty_project
,
:public
,
group:
group
)
}
let
(
:project2
)
{
create
(
:empty_project
,
:public
,
group:
group
)
}
let
(
:iterations
)
{
500
}
before
do
2
.
times
do
create
(
:note_on_commit
,
project:
project1
)
end
create
(
:note_on_commit
,
project:
project2
)
end
describe
'without an explicit start date'
do
benchmark_subject
{
described_class
.
trending
.
to_a
}
it
{
is_expected
.
to
iterate_per_second
(
iterations
)
}
end
describe
'with an explicit start date'
do
let
(
:date
)
{
1
.
month
.
ago
}
benchmark_subject
{
described_class
.
trending
(
date
).
to_a
}
it
{
is_expected
.
to
iterate_per_second
(
iterations
)
}
end
end
end
spec/finders/trending_projects_finder_spec.rb
0 → 100644
View file @
69bcef32
require
'spec_helper'
describe
TrendingProjectsFinder
do
let
(
:user
)
{
build
(
:user
)
}
describe
'#execute'
do
describe
'without an explicit start date'
do
subject
{
described_class
.
new
}
it
'returns the trending projects'
do
relation
=
double
(
:ar_relation
)
allow
(
subject
).
to
receive
(
:projects_for
)
.
with
(
user
)
.
and_return
(
relation
)
allow
(
relation
).
to
receive
(
:trending
)
.
with
(
an_instance_of
(
ActiveSupport
::
TimeWithZone
))
end
end
describe
'with an explicit start date'
do
let
(
:date
)
{
2
.
months
.
ago
}
subject
{
described_class
.
new
}
it
'returns the trending projects'
do
relation
=
double
(
:ar_relation
)
allow
(
subject
).
to
receive
(
:projects_for
)
.
with
(
user
)
.
and_return
(
relation
)
allow
(
relation
).
to
receive
(
:trending
)
.
with
(
date
)
end
end
end
end
spec/models/project_spec.rb
View file @
69bcef32
...
@@ -423,4 +423,42 @@ describe Project do
...
@@ -423,4 +423,42 @@ describe Project do
it
{
expect
(
project
.
gitlab_ci?
).
to
be_truthy
}
it
{
expect
(
project
.
gitlab_ci?
).
to
be_truthy
}
it
{
expect
(
project
.
gitlab_ci_project
).
to
be_a
(
Ci
::
Project
)
}
it
{
expect
(
project
.
gitlab_ci_project
).
to
be_a
(
Ci
::
Project
)
}
end
end
describe
'.trending'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:project1
)
{
create
(
:empty_project
,
:public
,
group:
group
)
}
let
(
:project2
)
{
create
(
:empty_project
,
:public
,
group:
group
)
}
before
do
2
.
times
do
create
(
:note_on_commit
,
project:
project1
)
end
create
(
:note_on_commit
,
project:
project2
)
end
describe
'without an explicit start date'
do
subject
{
described_class
.
trending
.
to_a
}
it
'sorts Projects by the amount of notes in descending order'
do
expect
(
subject
).
to
eq
([
project1
,
project2
])
end
end
describe
'with an explicit start date'
do
let
(
:date
)
{
2
.
months
.
ago
}
subject
{
described_class
.
trending
(
date
).
to_a
}
before
do
2
.
times
do
create
(
:note_on_commit
,
project:
project2
,
created_at:
date
)
end
end
it
'sorts Projects by the amount of notes in descending order'
do
expect
(
subject
).
to
eq
([
project2
,
project1
])
end
end
end
end
end
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