rosshamish / classtime

university schedule generation and course data API
MIT License
16 stars 2 forks source link

Cache responses to common requests #99

Open rosshamish opened 9 years ago

rosshamish commented 9 years ago

Re: suggestion by, and conversation with, Eric Eidelberg

Keep a table of the number of times we get a request. Chances are, we're getting similar requests all the time. Even if people play with the sliders eventually, it's likely (or even nearly guaranteed) that the first schedule they generate will be with no preferences, and lots of people take the same course list.

Create two tables
  (request-counts) mapping request -> num times received this request 
  (responses) mapping request -> response (list of schedules)

On /api/sched-gen?q={request}, request-counts[request] += 1
if request-counts[request] > N:
  if not responses[request]:
    schedules = do_sched_gen(request)
    responses[request] = schedules
  return responses[request]

else:
  schedules = do_sched_gen(request)
  return schedules