mirror of
https://github.com/typesense/typesense.git
synced 2025-05-20 13:42:26 +08:00
Reduce export/import memory usage.
This commit is contained in:
parent
741dd338f0
commit
c1500fec81
@ -51,7 +51,10 @@ public:
|
||||
|
||||
bool is_res_start = true;
|
||||
h2o_send_state_t send_state = H2O_SEND_STATE_IN_PROGRESS;
|
||||
h2o_iovec_t res_body{};
|
||||
|
||||
std::string res_body;
|
||||
h2o_iovec_t res_buff;
|
||||
|
||||
h2o_iovec_t res_content_type{};
|
||||
int status = 0;
|
||||
const char* reason = nullptr;
|
||||
@ -64,8 +67,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void set_response(uint32_t status_code, const std::string& content_type, const std::string& body) {
|
||||
res_body = h2o_strdup(&req->pool, body.c_str(), SIZE_MAX);
|
||||
void set_response(uint32_t status_code, const std::string& content_type, std::string& body) {
|
||||
std::string().swap(res_body);
|
||||
res_body = std::move(body);
|
||||
res_buff = h2o_iovec_t{.base = res_body.data(), .len = res_body.size()};
|
||||
|
||||
if(is_res_start) {
|
||||
res_content_type = h2o_strdup(&req->pool, content_type.c_str(), SIZE_MAX);
|
||||
|
@ -504,6 +504,9 @@ int HttpServer::catch_all_handler(h2o_handler_t *_h2o_handler, h2o_req_t *req) {
|
||||
);
|
||||
*allocated_generator = custom_gen;
|
||||
|
||||
// ensures that the first response need not wait for previous chunk to be done sending
|
||||
response->notify();
|
||||
|
||||
//LOG(INFO) << "Init res: " << custom_gen->response << ", ref count: " << custom_gen->response.use_count();
|
||||
|
||||
if(root_resource == "multi_search") {
|
||||
@ -632,9 +635,6 @@ int HttpServer::async_req_cb(void *ctx, int is_end_stream) {
|
||||
|
||||
if(request->first_chunk_aggregate) {
|
||||
request->first_chunk_aggregate = false;
|
||||
|
||||
// ensures that the first response need not wait for previous chunk to be done sending
|
||||
response->notify();
|
||||
}
|
||||
|
||||
// default value for last_chunk_aggregate is false
|
||||
@ -821,7 +821,7 @@ void HttpServer::stream_response(stream_response_state_t& state) {
|
||||
h2o_start_response(req, state.generator);
|
||||
}
|
||||
|
||||
h2o_send(req, &state.res_body, 1, H2O_SEND_STATE_FINAL);
|
||||
h2o_send(req, &state.res_buff, 1, H2O_SEND_STATE_FINAL);
|
||||
h2o_dispose_request(req);
|
||||
|
||||
return ;
|
||||
@ -833,13 +833,13 @@ void HttpServer::stream_response(stream_response_state_t& state) {
|
||||
h2o_start_response(req, state.generator);
|
||||
}
|
||||
|
||||
if(state.res_body.len == 0 && state.send_state != H2O_SEND_STATE_FINAL) {
|
||||
if(state.res_buff.len == 0 && state.send_state != H2O_SEND_STATE_FINAL) {
|
||||
// without this guard, http streaming will break
|
||||
state.generator->proceed(state.generator, req);
|
||||
return;
|
||||
}
|
||||
|
||||
h2o_send(req, &state.res_body, 1, state.send_state);
|
||||
h2o_send(req, &state.res_buff, 1, state.send_state);
|
||||
|
||||
//LOG(INFO) << "stream_response after send";
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user