Changing a site setting via the rails console is the same as doing it through the UI (just for the hidden ones there is no UI ), so the change will stick and not be affected by rebuilds or restarts, etc.
My knowledge on running them through the API is not as good as the regular way, but I think there’s a method of getting the full 10,000 without changing the setting in the rails console in this topic - Run Data Explorer queries with the Discourse API