Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
Qpixel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
EIP
Answers
Qpixel
Commits
6bd16661
Commit
6bd16661
authored
Dec 15, 2023
by
Taico Aerts
Browse files
Options
Downloads
Patches
Plain Diff
Fix the number of searches graph
parent
830a2ee0
Branches
Branches containing commit
No related tags found
1 merge request
!81
Fix the number of searches graph
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/controllers/analytics_dashboard_controller.rb
+1
-0
1 addition, 0 deletions
app/controllers/analytics_dashboard_controller.rb
app/helpers/analytics_dashboard_helper.rb
+20
-13
20 additions, 13 deletions
app/helpers/analytics_dashboard_helper.rb
with
21 additions
and
13 deletions
app/controllers/analytics_dashboard_controller.rb
+
1
−
0
View file @
6bd16661
...
...
@@ -58,6 +58,7 @@ class AnalyticsDashboardController < ApplicationController
def
searches_per_tag_chart
options
=
{
tags:
params
[
:tags
].
presence
,
start_date:
params
[
:start_date
].
presence
,
end_date:
params
[
:end_date
].
presence
,
top_n:
params
[
:top_n
].
presence
&
.
to_i
...
...
...
...
This diff is collapsed.
Click to expand it.
app/helpers/analytics_dashboard_helper.rb
+
20
−
13
View file @
6bd16661
module
AnalyticsDashboardHelper
# rubocop:disable Metrics/ParameterLists
def
number_of_searches_per_tag
(
start_date:
nil
,
end_date:
nil
,
top_n:
10
)
def
number_of_searches_per_tag
(
tags:
nil
,
start_date:
nil
,
end_date:
nil
,
top_n:
10
)
top_n
||=
10
hash
=
{}
searched_tag_counts
=
{}
searched_tag_counts_by_id
=
{}
base
=
ActionLog
.
where
(
controller_name:
'search'
,
controller_action_name:
'search'
)
base
=
base
.
where
(
created_at:
start_date
..
end_date
)
if
start_date
.
present?
||
end_date
.
present?
base
.
find_each
do
|
result
|
...
...
@@ -19,25 +20,31 @@ module AnalyticsDashboardHelper
value
=
splat
[
1
]
# Only take the 'tag' qualifiers from the string and add them to result
if
parameter
==
'tag'
hash
[
value
]
=
hash
.
fetch
(
value
,
0
)
+
1
searched_tag_counts
[
value
]
=
searched_tag_counts
.
fetch
(
value
,
0
)
+
1
end
end
end
# Extract the parameters from 'include_tags' parameters
if
params_hash
[
'include_tags'
].
present?
valid_value
=
{
integer:
/^\d+$/
}
# Filter only the valid ids - check that they are integers
tags_ids
=
params
[
:include_tags
]
&
.
all?
{
|
id
|
id
.
match?
valid_value
[
:integer
]
}
Tag
.
where
(
tags_ids
).
select
(
:name
).
find_each
do
|
tag
|
hash
[
tag
.
name
]
=
hash
.
fetch
(
tag
.
name
,
0
)
+
1
included_tags
=
params_hash
[
'included_tags'
]
&
.
grep
(
/\d+/
,
&
:to_i
)
if
included_tags
.
present?
included_tags
.
each
do
|
tag_id
|
searched_tag_counts_by_id
[
tag_id
]
=
searched_tag_counts_by_id
.
fetch
(
tag_id
,
0
)
+
1
end
end
end
puts
hash
# Convert the tags by id to the other format
Tag
.
where
(
id:
searched_tag_counts_by_id
.
keys
).
select
(
:id
,
:name
).
find_each
do
|
tag
|
searched_tag_counts
[
tag
.
name
]
=
searched_tag_counts
.
fetch
(
tag
.
name
,
0
)
+
searched_tag_counts_by_id
[
tag
.
id
]
end
# Filter to only the selected tags
if
tags
.
present?
searched_tag_counts
.
slice!
(
Tag
.
where
(
id:
tags
).
pluck
(
:name
))
end
# Take top 10 keys with largest values
hash
.
sort_by
{
|
_
,
v
|
-
v
}.
first
(
top_n
)
searched_tag_counts
.
sort_by
{
|
_
,
v
|
-
v
}.
first
(
top_n
)
end
def
currently_searched
...
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment