How does the number of times you need to check compare with the number of values ββstored in the database? If it is 1: 100, then yours probably would be better to search the database every time if it (some amount) is less than preloading the list will be faster. What happened when you tested it?
However, even if this ratio is low enough to speed up the loading of the full table, it will burn the memory and, as a result, will do the rest more slowly.
Therefore, I would recommend not loading all of this into memory. But if you can, then batch checks to minimize the number of rounds of trips to the database.
FROM.
source share