Resetting the database takes linear time O(n) dependent on the current exercise because all solutions before this have to be executed to enable student to work on any exercises even if they did not do the previous.
This could be solved with concating the setup script and the solutions. However this requires extensive testing and unit tests.
An alternative or an additional point would be to do these pg_stud request asynchronously.