classtime icon indicating copy to clipboard operation
classtime copied to clipboard

Cache responses to common requests

Open rosshamish opened this issue 10 years ago • 0 comments

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

rosshamish avatar Mar 25 '15 01:03 rosshamish