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
d9b627dc
Commit
d9b627dc
authored
Mar 25, 2021
by
Quang-Minh Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce Jira DVCS timestamp update frequence to once per day
Issue
https://gitlab.com/gitlab-org/gitlab/-/issues/325638
parent
0dff1ecb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
11 deletions
+98
-11
app/models/project_feature_usage.rb
app/models/project_feature_usage.rb
+18
-1
spec/models/project_feature_usage_spec.rb
spec/models/project_feature_usage_spec.rb
+80
-10
No files found.
app/models/project_feature_usage.rb
View file @
d9b627dc
...
...
@@ -20,7 +20,24 @@ class ProjectFeatureUsage < ApplicationRecord
end
def
log_jira_dvcs_integration_usage
(
cloud:
true
)
assign_attributes
(
self
.
class
.
jira_dvcs_integration_field
(
cloud:
cloud
)
=>
Time
.
current
)
integration_field
=
self
.
class
.
jira_dvcs_integration_field
(
cloud:
cloud
)
# The feature usage is used only once later to query the feature usage in a
# long date range. Therefore, we just need to update the timestamp once per
# day
return
if
persisted?
&&
updated_today?
(
integration_field
)
persist_jira_dvcs_usage
(
integration_field
)
end
private
def
updated_today?
(
integration_field
)
self
[
integration_field
].
present?
&&
self
[
integration_field
].
today?
end
def
persist_jira_dvcs_usage
(
integration_field
)
assign_attributes
(
integration_field
=>
Time
.
current
)
save
rescue
ActiveRecord
::
RecordNotUnique
reset
...
...
spec/models/project_feature_usage_spec.rb
View file @
d9b627dc
...
...
@@ -24,21 +24,91 @@ RSpec.describe ProjectFeatureUsage, type: :model do
subject
{
project
.
feature_usage
}
it
'logs Jira DVCS Cloud last sync'
do
freeze_time
do
subject
.
log_jira_dvcs_integration_usage
context
'when the feature usage has not been created yet'
do
it
'logs Jira DVCS Cloud last sync'
do
freeze_time
do
subject
.
log_jira_dvcs_integration_usage
expect
(
subject
.
jira_dvcs_server_last_sync_at
).
to
be_nil
expect
(
subject
.
jira_dvcs_cloud_last_sync_at
).
to
be_like_time
(
Time
.
current
)
expect
(
subject
.
jira_dvcs_server_last_sync_at
).
to
be_nil
expect
(
subject
.
jira_dvcs_cloud_last_sync_at
).
to
be_like_time
(
Time
.
current
)
end
end
it
'logs Jira DVCS Server last sync'
do
freeze_time
do
subject
.
log_jira_dvcs_integration_usage
(
cloud:
false
)
expect
(
subject
.
jira_dvcs_server_last_sync_at
).
to
be_like_time
(
Time
.
current
)
expect
(
subject
.
jira_dvcs_cloud_last_sync_at
).
to
be_nil
end
end
end
it
'logs Jira DVCS Server last sync'
do
freeze_time
do
subject
.
log_jira_dvcs_integration_usage
(
cloud:
false
)
context
'when the feature usage already exists'
do
let
(
:today
)
{
Time
.
current
.
beginning_of_day
}
let
(
:project
)
{
create
(
:project
)
}
subject
{
project
.
feature_usage
}
expect
(
subject
.
jira_dvcs_server_last_sync_at
).
to
be_like_time
(
Time
.
current
)
expect
(
subject
.
jira_dvcs_cloud_last_sync_at
).
to
be_nil
where
(
:cloud
,
:timestamp_field
)
do
[
[
true
,
:jira_dvcs_cloud_last_sync_at
],
[
false
,
:jira_dvcs_server_last_sync_at
]
]
end
with_them
do
context
'when Jira DVCS Cloud last sync has not been logged'
do
before
do
travel_to
today
-
3
.
days
do
subject
.
log_jira_dvcs_integration_usage
(
cloud:
!
cloud
)
end
end
it
'logs Jira DVCS Cloud last sync'
do
freeze_time
do
subject
.
log_jira_dvcs_integration_usage
(
cloud:
cloud
)
expect
(
subject
.
reload
.
send
(
timestamp_field
)).
to
be_like_time
(
Time
.
current
)
end
end
end
context
'when Jira DVCS Cloud last sync was logged today'
do
let
(
:last_updated
)
{
today
+
1
.
hour
}
before
do
travel_to
last_updated
do
subject
.
log_jira_dvcs_integration_usage
(
cloud:
cloud
)
end
end
it
'does not log Jira DVCS Cloud last sync'
do
travel_to
today
+
2
.
hours
do
subject
.
log_jira_dvcs_integration_usage
(
cloud:
cloud
)
expect
(
subject
.
reload
.
send
(
timestamp_field
)).
to
be_like_time
(
last_updated
)
end
end
end
context
'when Jira DVCS Cloud last sync was logged yesterday'
do
let
(
:last_updated
)
{
today
-
2
.
days
}
before
do
travel_to
last_updated
do
subject
.
log_jira_dvcs_integration_usage
(
cloud:
cloud
)
end
end
it
'logs Jira DVCS Cloud last sync'
do
travel_to
today
+
1
.
hour
do
subject
.
log_jira_dvcs_integration_usage
(
cloud:
cloud
)
expect
(
subject
.
reload
.
send
(
timestamp_field
)).
to
be_like_time
(
today
+
1
.
hour
)
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