Skip to content

Commit a209e90

Browse files
jpnurmiclaude
andcommitted
refactor(database): hoist directory creation out of per-item loop
resolve_large_attachment called sentry__path_create_dir_all per attachment item. Move the directory creation into the caller so it happens once before the loop. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f0878bf commit a209e90

1 file changed

Lines changed: 16 additions & 23 deletions

File tree

src/sentry_database.c

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -177,27 +177,9 @@ resolve_large_attachment_dir(const sentry_path_t *db_path, const char *uuid_str)
177177
return event_dir;
178178
}
179179

180-
static sentry_path_t *
181-
resolve_large_attachment(
182-
const sentry_path_t *db_path, const char *uuid_str, const char *filename)
183-
{
184-
sentry_path_t *event_dir = resolve_large_attachment_dir(db_path, uuid_str);
185-
if (!event_dir) {
186-
return NULL;
187-
}
188-
if (sentry__path_create_dir_all(event_dir) != 0) {
189-
sentry__path_free(event_dir);
190-
return NULL;
191-
}
192-
sentry_path_t *dst = sentry__path_join_str(event_dir, filename);
193-
sentry__path_free(event_dir);
194-
return dst;
195-
}
196-
197180
static void
198181
write_large_attachment(sentry_envelope_item_t *item,
199-
const sentry_path_t *db_path, const char *uuid_str,
200-
const sentry_path_t *run_path)
182+
const sentry_path_t *event_dir, const sentry_path_t *run_path)
201183
{
202184
const char *filename = sentry_value_as_string(
203185
sentry__envelope_item_get_header(item, "filename"));
@@ -218,7 +200,7 @@ write_large_attachment(sentry_envelope_item_t *item,
218200
if (!payload || payload_len == 0) {
219201
return;
220202
}
221-
dst = resolve_large_attachment(db_path, uuid_str, filename);
203+
dst = sentry__path_join_str(event_dir, filename);
222204
if (!dst) {
223205
return;
224206
}
@@ -232,7 +214,7 @@ write_large_attachment(sentry_envelope_item_t *item,
232214
sentry_path_t *src_dir = sentry__path_dir(src);
233215
bool is_run_owned = src_dir && sentry__path_eq(src_dir, run_path);
234216
sentry__path_free(src_dir);
235-
dst = resolve_large_attachment(db_path, uuid_str, filename);
217+
dst = sentry__path_join_str(event_dir, filename);
236218
if (!dst) {
237219
sentry__path_free(src);
238220
return;
@@ -269,15 +251,26 @@ sentry__run_write_envelope(const sentry_run_t *run, sentry_envelope_t *envelope)
269251
char uuid_str[37];
270252
sentry_uuid_as_string(&event_id, uuid_str);
271253

254+
sentry_path_t *event_dir
255+
= resolve_large_attachment_dir(db_path, uuid_str);
256+
sentry__path_free(db_path);
257+
if (!event_dir) {
258+
return false;
259+
}
260+
if (sentry__path_create_dir_all(event_dir) != 0) {
261+
sentry__path_free(event_dir);
262+
return false;
263+
}
264+
272265
size_t count = sentry__envelope_get_item_count(envelope);
273266
for (size_t i = 0; i < count; i++) {
274267
sentry_envelope_item_t *item
275268
= sentry__envelope_get_item_mut(envelope, i);
276269
if (sentry__envelope_item_is_attachment_ref(item)) {
277-
write_large_attachment(item, db_path, uuid_str, run->run_path);
270+
write_large_attachment(item, event_dir, run->run_path);
278271
}
279272
}
280-
sentry__path_free(db_path);
273+
sentry__path_free(event_dir);
281274
}
282275
return write_envelope(run->run_path, envelope, -1);
283276
}

0 commit comments

Comments
 (0)