Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit18b45c2

Browse files
committed
delete in batches
1 parent1df93be commit18b45c2

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

‎coderd/database/dbmem/dbmem.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,15 @@ func (q *FakeQuerier) DeleteOldWorkspaceAgentStats(_ context.Context) error {
15261526
)
15271527
FROM
15281528
template_usage_stats
1529+
)
1530+
AND created_at < (
1531+
-- Delete at most in batches of 3 days (with a batch size of 3 days, we
1532+
-- can clear out the previous 6 months of data in ~60 iterations) whilst
1533+
-- keeping the DB load relatively low.
1534+
SELECT
1535+
COALESCE(MIN(created_at) + '3 days'::interval, NOW())
1536+
FROM
1537+
workspace_agent_stats
15291538
);
15301539
*/
15311540

@@ -1543,10 +1552,19 @@ func (q *FakeQuerier) DeleteOldWorkspaceAgentStats(_ context.Context) error {
15431552
}
15441553

15451554
varvalidStats []database.WorkspaceAgentStat
1555+
varbatchLimit time.Time
1556+
for_,stat:=rangeq.workspaceAgentStats {
1557+
ifbatchLimit.IsZero()||stat.CreatedAt.Before(batchLimit) {
1558+
batchLimit=stat.CreatedAt
1559+
}
1560+
}
1561+
ifbatchLimit.IsZero() {
1562+
batchLimit=time.Now()
1563+
}else {
1564+
batchLimit=batchLimit.AddDate(0,0,3)
1565+
}
15461566
for_,stat:=rangeq.workspaceAgentStats {
1547-
fmt.Println(stat.CreatedAt,limit)
1548-
ifstat.CreatedAt.Before(limit) {
1549-
fmt.Println("delete")
1567+
ifstat.CreatedAt.Before(limit)&&stat.CreatedAt.Before(batchLimit) {
15501568
continue
15511569
}
15521570
validStats=append(validStats,stat)

‎coderd/database/queries.sql.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/workspaceagentstats.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ WHERE
109109
)
110110
FROM
111111
template_usage_stats
112+
)
113+
AND created_at< (
114+
-- Delete at most in batches of 3 days (with a batch size of 3 days, we
115+
-- can clear out the previous 6 months of data in ~60 iterations) whilst
116+
-- keeping the DB load relatively low.
117+
SELECT
118+
COALESCE(MIN(created_at)+'3 days'::interval, NOW())
119+
FROM
120+
workspace_agent_stats
112121
);
113122

114123
-- name: GetDeploymentWorkspaceAgentStats :one

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp