Fix Multiple Api pulls / cache Until update.

Moved a number of database queries outside of foreach loops as they are used to set the cache until.
Causing redundant queries in previous location.