SearchJob: don't assemble OR term recursively
Summary:
The code was ridiculously inefficient for large OR sets. Trying
to assemble an OR term with 28'000 subterms took minutes and the
process eventually ran out of memory. Instead just use a for loop
and a bit of counting to balance the parentheses, the string
is assembled within milliseconds.
Test Plan:
Added a test to make sure the serialized string is the same as before
A benchmark for 10'000 subterms took 4 seconds. Benchmark for 28'000
subterms got killed by the OOM-killer. After the patch the benchmark
for 28'000 subterms took 2.2 ms.
Reviewers: KDE PIM, vkrause
Reviewed By: KDE PIM, vkrause
Subscribers: kde-pim
Tags: KDE PIM
Differential Revision: https://phabricator.kde.org/D28946