SaturDJang / warp

Warp is a web based markdown presentation service
MIT License
13 stars 6 forks source link

Optimize query for all views #143

Closed myungseokang closed 7 years ago

myungseokang commented 7 years ago

I saw index page's SQL query count maybe 11. many duplicated query exists. So need to optimizing query.

kyunooh commented 7 years ago

I think doesn't need to optimize. Cause there is no bottleneck. If each data have different author, then there are no duplicated queries. It depends on the data. All duplicated queries on the index are selected by primary key. It is fast enough. There is way to optimize, but it would be have problem with readability. It is enough to optimize when we have a problem with slow queries. We have to focus on to implement a feature.

Any improvements made anywhere besides the bottleneck are an illusion. — Gene Kim

We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%. — Donald Ervin Knuth

myungseokang commented 7 years ago

But just adding 2 lines to PresentationList class, query's count decrease 11 to 2. I do not think I need to leave a visible inefficient part.

class PresentationList(PaginationMixin, ListView):
    model = Presentation
    paginate_by = 9
    context_object_name = 'presentations'
    ordering = ['-pk']

    # here
    def get_queryset(self):
        return Presentation.objects.all().select_related('author')
qkraudghgh commented 7 years ago

@Leop0ld Do it!

myungseokang commented 7 years ago

@qkraudghgh I need to review other views. I create PR if I finish task.

kyunooh commented 7 years ago

:+1: