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
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
c27c8133
Commit
c27c8133
authored
Aug 26, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve trending projects finder
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
6c23fd38
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
5 deletions
+13
-5
app/finders/trending_projects_finder.rb
app/finders/trending_projects_finder.rb
+13
-5
No files found.
app/finders/trending_projects_finder.rb
View file @
c27c8133
...
...
@@ -2,13 +2,21 @@ class TrendingProjectsFinder
def
execute
(
current_user
,
start_date
=
nil
)
start_date
||=
Date
.
today
-
1
.
month
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
).
select
(
"projects.*, count(notes.id) as ncount"
).
group
(
"projects.id"
).
reorder
(
"ncount DESC"
)
trending_project_ids
=
Note
.
select
(
"notes.project_id, count(notes.project_id) as pcount"
).
where
(
'notes.created_at > ?'
,
start_date
).
group
(
"project_id"
).
reorder
(
"pcount DESC"
).
map
(
&
:project_id
)
sql_order_ids
=
trending_project_ids
.
reverse
.
map
{
|
project_id
|
"id =
#{
project_id
}
"
}.
join
(
", "
)
# Get list of projects that user allowed to see
projects
=
projects_for
(
current_user
)
projects
.
where
(
id:
trending_project_ids
).
reorder
(
sql_order_ids
)
end
private
...
...
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