Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
3f85fcce
Commit
3f85fcce
authored
Mar 21, 2018
by
Alexander Zobnin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: dashboard version cleanup
parent
f976b690
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
13 deletions
+15
-13
pkg/services/sqlstore/dashboard_version.go
+15
-13
No files found.
pkg/services/sqlstore/dashboard_version.go
View file @
3f85fcce
...
...
@@ -81,7 +81,7 @@ func DeleteExpiredVersions(cmd *m.DeleteExpiredVersionsCommand) error {
// min_version_to_keep = min_version + (versions_count - versions_to_keep)
// where version stats is processed for each dashboard. This guarantees that we keep at least versions_to_keep
// versions, but in some cases (when versions are sparse) this number may be more.
versionIdsToDeleteS
y
bqueryTemplate
:=
`SELECT id
versionIdsToDeleteS
u
bqueryTemplate
:=
`SELECT id
FROM dashboard_version, (
SELECT dashboard_id, count(version) as count, min(version) as min
FROM dashboard_version
...
...
@@ -90,26 +90,28 @@ func DeleteExpiredVersions(cmd *m.DeleteExpiredVersionsCommand) error {
WHERE dashboard_version.dashboard_id=vtd.dashboard_id
AND version < vtd.min + vtd.count - %v`
versionIdsToDeleteSubquery
:=
fmt
.
Sprintf
(
versionIdsToDeleteS
y
bqueryTemplate
,
versionsToKeep
)
v
ersions
:=
[]
string
{}
err
:=
sess
.
SQL
(
versionIdsToDeleteSubquery
)
.
Find
(
&
version
s
)
versionIdsToDeleteSubquery
:=
fmt
.
Sprintf
(
versionIdsToDeleteS
u
bqueryTemplate
,
versionsToKeep
)
v
ar
versionIdsToDelete
[]
interface
{}
err
:=
sess
.
SQL
(
versionIdsToDeleteSubquery
)
.
Find
(
&
version
IdsToDelete
)
if
err
!=
nil
{
return
err
}
// Don't delete more than MAX_VERSIONS_TO_DELETE version per time
limit
:=
MAX_VERSIONS_TO_DELETE
if
len
(
version
s
)
<
MAX_VERSIONS_TO_DELETE
{
limit
=
len
(
version
s
)
if
len
(
version
IdsToDelete
)
<
MAX_VERSIONS_TO_DELETE
{
limit
=
len
(
version
IdsToDelete
)
}
versions
=
versions
[
:
limit
]
deleteExpiredSql
:=
fmt
.
Sprintf
(
`DELETE FROM dashboard_version WHERE id IN (%s)`
,
strings
.
Join
(
versions
,
`,`
))
expiredResponse
,
err
:=
sess
.
Exec
(
deleteExpiredSql
)
if
err
!=
nil
{
return
err
versionIdsToDelete
=
versionIdsToDelete
[
:
limit
]
if
len
(
versionIdsToDelete
)
>
0
{
deleteExpiredSql
:=
`DELETE FROM dashboard_version WHERE id IN (?`
+
strings
.
Repeat
(
",?"
,
len
(
versionIdsToDelete
)
-
1
)
+
`)`
expiredResponse
,
err
:=
sess
.
Exec
(
deleteExpiredSql
,
versionIdsToDelete
...
)
if
err
!=
nil
{
return
err
}
cmd
.
DeletedRows
,
_
=
expiredResponse
.
RowsAffected
()
}
cmd
.
DeletedRows
,
_
=
expiredResponse
.
RowsAffected
()
return
nil
})
...
...
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