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

Commit336c7b8

Browse files
committed
rewrite queries, single upsert
1 parent217a0d3 commit336c7b8

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
-- name: InsertWorkspaceAppAuditSession :one
1+
-- name: UpsertWorkspaceAppAuditSession :one
2+
--
3+
-- Insert a new workspace app audit session or update an existing one, if
4+
-- started_at is updated, it means the session has been restarted.
25
INSERT INTO
36
workspace_app_audit_sessions (
47
agent_id,
58
app_id,
69
user_id,
710
ip,
11+
user_agent,
812
slug_or_port,
13+
status_code,
914
started_at,
1015
updated_at
1116
)
@@ -17,25 +22,20 @@ VALUES
1722
$4,
1823
$5,
1924
$6,
20-
$7
25+
$7,
26+
$8,
27+
$9
2128
)
29+
ON CONFLICT
30+
(agent_id, app_id, user_id, ip, user_agent, slug_or_port, status_code)
31+
DO
32+
UPDATE
33+
SET
34+
started_at= CASE
35+
WHENworkspace_app_audit_sessions.updated_at> NOW()- (@stale_interval_ms::bigint||' ms')::interval
36+
THENworkspace_app_audit_sessions.started_at
37+
ELSEEXCLUDED.started_at
38+
END,
39+
updated_at=EXCLUDED.updated_at
2240
RETURNING
23-
id;
24-
25-
-- name: UpdateWorkspaceAppAuditSession :many
26-
--
27-
-- Return ID to determine if a row was updated or not. This table isn't strict
28-
-- about uniqueness, so we need to know if we updated an existing row or not.
29-
UPDATE
30-
workspace_app_audit_sessions
31-
SET
32-
updated_at= @updated_at
33-
WHERE
34-
agent_id= @agent_id
35-
AND app_id IS NOT DISTINCTFROM @app_id
36-
AND user_id IS NOT DISTINCTFROM @user_id
37-
AND ip IS NOT DISTINCTFROM @ip
38-
AND slug_or_port= @slug_or_port
39-
AND updated_at> NOW()- (@stale_interval_ms::bigint||' ms')::interval
40-
RETURNING
41-
id;
41+
started_at;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp