peopledoc / django-chartjs

Django Class Based Views to generate Ajax charts js parameters.
Other
407 stars 112 forks source link

Multiple get_data() Calls from API #16

Closed mikelorengo closed 9 years ago

mikelorengo commented 9 years ago

I'd like to discuss a piece of code found in the current build: /chartjs/views/lines.py

Synopsis: Two calls are being made to get_data(), slowing down my response time. How do I know this is a problem? See bottom of page on how to reproduce this issue.

Use Case, or Why this is a problem: My custom get_data() function depends heavily on aggregating a lot of data. In some cases, the aggregation could take a couple of seconds. If this function is called twice, that doubles the response time. Aggregation must be handled in the get_data() function to pass the info along to the chart.

Situation Summary: The stub is in my chart mixin, the function called is get_data().

From lines.py

code

Is it possible to reduce this to one function call to save my database some stress?

Testing to find this issue (how to reproduce): I did run-time testing using print commands in the custom get_data() function where the console reported twice for the same event on invoking the mix-in once by ajax. Confirmed single invocation in the debugger. To track specifically where this was coming from, I inserted: if name == 'main' above the "def get_data()" in my mix-in. It was able to track down the caller, which came from /chartjs/views/lines.py where this module is located.

Suggestions? Anyone want to take a crack at it?

Natim commented 9 years ago

Well we should probably use data instead of self.get_data in the enumerate for loop.