Skip to content

Commit 4c087ae

Browse files
committed
Test parallelized item loading
1 parent 2897149 commit 4c087ae

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

Today.cpp

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -242,41 +242,47 @@ struct EdgeConstraints
242242

243243
std::future<std::shared_ptr<object::AppointmentConnection>> Query::getAppointments(service::RequestId requestId, std::unique_ptr<int>&& first, std::unique_ptr<rapidjson::Value>&& after, std::unique_ptr<int>&& last, std::unique_ptr<rapidjson::Value>&& before) const
244244
{
245-
loadAppointments();
246-
247-
std::promise<std::shared_ptr<object::AppointmentConnection>> promise;
248-
EdgeConstraints<Appointment, AppointmentConnection> constraints(requestId, _appointments);
249-
auto connection = constraints(first.get(), after.get(), last.get(), before.get());
245+
auto spThis = shared_from_this();
246+
return std::async(std::launch::async,
247+
[this, spThis](service::RequestId requestIdWrapped, std::unique_ptr<int>&& firstWrapped, std::unique_ptr<rapidjson::Value>&& afterWrapped, std::unique_ptr<int>&& lastWrapped, std::unique_ptr<rapidjson::Value>&& beforeWrapped)
248+
{
249+
loadAppointments();
250250

251-
promise.set_value(std::static_pointer_cast<object::AppointmentConnection>(connection));
251+
EdgeConstraints<Appointment, AppointmentConnection> constraints(requestIdWrapped, _appointments);
252+
auto connection = constraints(firstWrapped.get(), afterWrapped.get(), lastWrapped.get(), beforeWrapped.get());
252253

253-
return promise.get_future();
254+
return std::static_pointer_cast<object::AppointmentConnection>(connection);
255+
}, requestId, std::move(first), std::move(after), std::move(last), std::move(before));
254256
}
255257

256258
std::future<std::shared_ptr<object::TaskConnection>> Query::getTasks(service::RequestId requestId, std::unique_ptr<int>&& first, std::unique_ptr<rapidjson::Value>&& after, std::unique_ptr<int>&& last, std::unique_ptr<rapidjson::Value>&& before) const
257259
{
258-
loadTasks();
259-
260-
std::promise<std::shared_ptr<object::TaskConnection>> promise;
261-
EdgeConstraints<Task, TaskConnection> constraints(requestId, _tasks);
262-
auto connection = constraints(first.get(), after.get(), last.get(), before.get());
260+
auto spThis = shared_from_this();
261+
return std::async(std::launch::async,
262+
[this, spThis](service::RequestId requestIdWrapped, std::unique_ptr<int>&& firstWrapped, std::unique_ptr<rapidjson::Value>&& afterWrapped, std::unique_ptr<int>&& lastWrapped, std::unique_ptr<rapidjson::Value>&& beforeWrapped)
263+
{
264+
loadTasks();
263265

264-
promise.set_value(std::static_pointer_cast<object::TaskConnection>(connection));
266+
EdgeConstraints<Task, TaskConnection> constraints(requestIdWrapped, _tasks);
267+
auto connection = constraints(firstWrapped.get(), afterWrapped.get(), lastWrapped.get(), beforeWrapped.get());
265268

266-
return promise.get_future();
269+
return std::static_pointer_cast<object::TaskConnection>(connection);
270+
}, requestId, std::move(first), std::move(after), std::move(last), std::move(before));
267271
}
268272

269273
std::future<std::shared_ptr<object::FolderConnection>> Query::getUnreadCounts(service::RequestId requestId, std::unique_ptr<int>&& first, std::unique_ptr<rapidjson::Value>&& after, std::unique_ptr<int>&& last, std::unique_ptr<rapidjson::Value>&& before) const
270274
{
271-
loadUnreadCounts();
272-
273-
std::promise<std::shared_ptr<object::FolderConnection>> promise;
274-
EdgeConstraints<Folder, FolderConnection> constraints(requestId, _unreadCounts);
275-
auto connection = constraints(first.get(), after.get(), last.get(), before.get());
275+
auto spThis = shared_from_this();
276+
return std::async(std::launch::async,
277+
[this, spThis](service::RequestId requestIdWrapped, std::unique_ptr<int>&& firstWrapped, std::unique_ptr<rapidjson::Value>&& afterWrapped, std::unique_ptr<int>&& lastWrapped, std::unique_ptr<rapidjson::Value>&& beforeWrapped)
278+
{
279+
loadUnreadCounts();
276280

277-
promise.set_value(std::static_pointer_cast<object::FolderConnection>(connection));
281+
EdgeConstraints<Folder, FolderConnection> constraints(requestIdWrapped, _unreadCounts);
282+
auto connection = constraints(firstWrapped.get(), afterWrapped.get(), lastWrapped.get(), beforeWrapped.get());
278283

279-
return promise.get_future();
284+
return std::static_pointer_cast<object::FolderConnection>(connection);
285+
}, requestId, std::move(first), std::move(after), std::move(last), std::move(before));
280286
}
281287

282288
std::future<std::vector<std::shared_ptr<object::Appointment>>> Query::getAppointmentsById(service::RequestId requestId, std::vector<std::vector<uint8_t>>&& ids) const

0 commit comments

Comments
 (0)