I suggest try another approach that I did in a Magento 1 store: instead of try rewrite how the resource/collection is assembled, create a new attribute in native way for best seller (save the qty of purchases) and create an extension with a cron to populate the data in this field.
Using this way the core feature of sort of Magento will works as expected in any scenario. Of course it won't be in real time. In my case with Magento 1 I did a cron that update best seller attribute in the products every day at midnight.
So a quick list with the steps for you:
- Create the extension with a crontab job.
- Create the attribute to storage the quantity of sales for products (you can created it inside the admin panel if you want). Make sure to make it usable to sort and set this attribute to default sort attribute in Magento admin.
- Create a model with a function to get the sales order items created since last execution (last 24h) and update the product's bestseller attribute increasing the number.
- Do a customization to change the default direction of sort because you want the bigger number first (DESC direction). This link can help you: https://www.customerparadigm.com/changing-default-product-sorting-in-magento-2/
Also in github there are some extensions for get it, but I never tested in Magento 2:
In the end there is a third way to try it: Instead of create a cron to fill the attribute for qty of purchases, you can create an event to increment the attribute after place each order. But I don't like this way because can impact the time to place an order.