the_post_thumbnail do 2 queries. How to optimize

use caching plugins, that is why they exist – to offload work from the DB.

If you don’t want to do full page caching and you know that the resulting HTML do not change much you can use transients to store the result for something like an hour before recalculating it.

error code: 523