|
4 | 4 |
|
5 | 5 | import type { CachedProject } from "../../types/index.js"; |
6 | 6 | import { getDatabase, maybeCleanupCaches } from "./index.js"; |
| 7 | +import { runUpsert } from "./utils.js"; |
7 | 8 |
|
8 | 9 | type ProjectCacheRow = { |
9 | 10 | cache_key: string; |
@@ -68,25 +69,19 @@ export async function setCachedProject( |
68 | 69 | const key = projectCacheKey(orgId, projectId); |
69 | 70 | const now = Date.now(); |
70 | 71 |
|
71 | | - db.query(` |
72 | | - INSERT INTO project_cache |
73 | | - (cache_key, org_slug, org_name, project_slug, project_name, cached_at, last_accessed) |
74 | | - VALUES (?, ?, ?, ?, ?, ?, ?) |
75 | | - ON CONFLICT(cache_key) DO UPDATE SET |
76 | | - org_slug = excluded.org_slug, |
77 | | - org_name = excluded.org_name, |
78 | | - project_slug = excluded.project_slug, |
79 | | - project_name = excluded.project_name, |
80 | | - cached_at = excluded.cached_at, |
81 | | - last_accessed = excluded.last_accessed |
82 | | - `).run( |
83 | | - key, |
84 | | - info.orgSlug, |
85 | | - info.orgName, |
86 | | - info.projectSlug, |
87 | | - info.projectName, |
88 | | - now, |
89 | | - now |
| 72 | + runUpsert( |
| 73 | + db, |
| 74 | + "project_cache", |
| 75 | + { |
| 76 | + cache_key: key, |
| 77 | + org_slug: info.orgSlug, |
| 78 | + org_name: info.orgName, |
| 79 | + project_slug: info.projectSlug, |
| 80 | + project_name: info.projectName, |
| 81 | + cached_at: now, |
| 82 | + last_accessed: now, |
| 83 | + }, |
| 84 | + ["cache_key"] |
90 | 85 | ); |
91 | 86 |
|
92 | 87 | maybeCleanupCaches(); |
@@ -120,25 +115,19 @@ export async function setCachedProjectByDsnKey( |
120 | 115 | const key = dsnCacheKey(publicKey); |
121 | 116 | const now = Date.now(); |
122 | 117 |
|
123 | | - db.query(` |
124 | | - INSERT INTO project_cache |
125 | | - (cache_key, org_slug, org_name, project_slug, project_name, cached_at, last_accessed) |
126 | | - VALUES (?, ?, ?, ?, ?, ?, ?) |
127 | | - ON CONFLICT(cache_key) DO UPDATE SET |
128 | | - org_slug = excluded.org_slug, |
129 | | - org_name = excluded.org_name, |
130 | | - project_slug = excluded.project_slug, |
131 | | - project_name = excluded.project_name, |
132 | | - cached_at = excluded.cached_at, |
133 | | - last_accessed = excluded.last_accessed |
134 | | - `).run( |
135 | | - key, |
136 | | - info.orgSlug, |
137 | | - info.orgName, |
138 | | - info.projectSlug, |
139 | | - info.projectName, |
140 | | - now, |
141 | | - now |
| 118 | + runUpsert( |
| 119 | + db, |
| 120 | + "project_cache", |
| 121 | + { |
| 122 | + cache_key: key, |
| 123 | + org_slug: info.orgSlug, |
| 124 | + org_name: info.orgName, |
| 125 | + project_slug: info.projectSlug, |
| 126 | + project_name: info.projectName, |
| 127 | + cached_at: now, |
| 128 | + last_accessed: now, |
| 129 | + }, |
| 130 | + ["cache_key"] |
142 | 131 | ); |
143 | 132 |
|
144 | 133 | maybeCleanupCaches(); |
|
0 commit comments