Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions runtime/fastly/builtins/cache-simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,12 @@ bool get_or_set_then_handler(JSContext *cx, JS::HandleObject lookup_state, JS::H

auto inserted_res = handle.transaction_insert_and_stream_back(options);
if (auto *err = inserted_res.to_err()) {
HANDLE_ERROR(cx, *err);
return false;
}

transaction.commit();

auto [body, inserted_handle] = inserted_res.unwrap();
if (!body.valid()) {
return false;
Expand All @@ -348,19 +351,23 @@ bool get_or_set_then_handler(JSContext *cx, JS::HandleObject lookup_state, JS::H
if (source_body.valid()) {
auto res = body.append(source_body);
if (auto *error = res.to_err()) {
HANDLE_ERROR(cx, *err);
return false;
}
} else {
auto write_res = body.write_all_back(reinterpret_cast<uint8_t *>(buf.get()), options.length);
if (auto *error = write_res.to_err()) {
return false;
}
auto close_res = body.close();
if (auto *error = close_res.to_err()) {
HANDLE_ERROR(cx, *err);
return false;
}
}

auto close_res = body.close();
if (auto *error = close_res.to_err()) {
HANDLE_ERROR(cx, *err);
return false;
}

auto res = inserted_handle.get_body(host_api::CacheGetBodyOptions{});
if (auto *err = res.to_err()) {
HANDLE_ERROR(cx, *err);
Expand All @@ -372,8 +379,6 @@ bool get_or_set_then_handler(JSContext *cx, JS::HandleObject lookup_state, JS::H
return false;
}

transaction.commit();

JS::RootedValue result(cx);
result.setObject(*entry);
JS::ResolvePromise(cx, promise, result);
Expand Down
Loading