Accessing `valid_docs.ids` for each activity to check was costly, and in
my example the whole loop took 125 seconds to execute.
By turning it into a set, the same loop takes 0.2 seconds to execute.
When re-constructing the list based on ids to keep the order, using a
set is also faster, and takes another 0.2 seconds instead of 13.6.
closesodoo/odoo#79969
X-original-commit: f994db760b679c8acdaf4245315f89c1d31a9e1c
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>