Avoid repeating lots of queries every time

user9865749

I'm done building a website, there's a lots of views that contains many queries My question is How can I avoid repeating some queries from views that will be visited by users many time?.

Here is an example of views.py

@access_to(['is_admin','is_job_seeker'])
def negotiationView(request,slug,id,code):
    obj = get_object_or_404(Group,slug=slug) 
    nego = get_object_or_404(Negotiation,id=id,code=code)

    related_negos = Negotiation.objects.filter(tag=nego.tag)
    # New tag can be created every 2 months or more
    all_jobs = obj.job_offers.filter(published=True) # new job can be added every week

As you can, each time I visit that page, the same query will repeat..

Any hint will be helpful, Thank you in advance!

Maxim Kukhtenkov

You can add a caching layer to your application. One of the technologies that can be used with Django is Memcached.

Here's info in Django docs about setting up caching with Memcached: https://docs.djangoproject.com/en/2.0/topics/cache/#memcached

Also same page has info about using caching in Django in general, including per-view cache

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to avoid repeating blocks of XAML in a menu

分類Dev

How to avoid repeating the following replace code?

分類Dev

Django conditional queries: How can I avoid this?

分類Dev

Different result every time

分類Dev

accessibilityPerformMagicTap not called every time

分類Dev

How can I avoid repeating the css and not using !important?

分類Dev

How to avoid repeating sed commands when adding sites to Varnish?

分類Dev

Override ExecuteAsync Method to avoid repeating code of Web Api Action Method

分類Dev

How to avoid hardcode in every class WebClient retryWhen

分類Dev

Add response header to every handler without repeating the same line

分類Dev

Android - Checkbox repeating every 10th in a listview

分類Dev

Repeating a Local Notification after every 14 days(two weeks)?

分類Dev

Compile lots of TeX files at the same time (or with a single command)

分類Dev

Lots of queries on one page that take too long to execute... Can't seem to optimize them

分類Dev

RadioButtonList not firing SelectedIndexChanged every time

分類Dev

Getting the same answer every time

分類Dev

Avoid n+1 queries in Django admin list view

分類Dev

How to avoid N+1 queries in Rails "each" loops?

分類Dev

how to avoid high CPU usage when no active queries

分類Dev

Laravel View Composer duplicating SQL queries for every view

分類Dev

ASP.Net Identity running multiple queries on every request

分類Dev

Send email multiple time without repeating the email code

分類Dev

Avoid checking the same condition every step in a loop in C++

分類Dev

Avoid repeating the variable type: Return Type Resolver, C++11 auto, ...anything else?

分類Dev

typescript calling a function every specific time

分類Dev

SET working every other time Python MySQL

分類Dev

Makefile ignores dependency every other time

分類Dev

(Laravel) Update interface every time there is a change in the database?

分類Dev

How to write to a new line every time in python?

Related 関連記事

  1. 1

    How to avoid repeating blocks of XAML in a menu

  2. 2

    How to avoid repeating the following replace code?

  3. 3

    Django conditional queries: How can I avoid this?

  4. 4

    Different result every time

  5. 5

    accessibilityPerformMagicTap not called every time

  6. 6

    How can I avoid repeating the css and not using !important?

  7. 7

    How to avoid repeating sed commands when adding sites to Varnish?

  8. 8

    Override ExecuteAsync Method to avoid repeating code of Web Api Action Method

  9. 9

    How to avoid hardcode in every class WebClient retryWhen

  10. 10

    Add response header to every handler without repeating the same line

  11. 11

    Android - Checkbox repeating every 10th in a listview

  12. 12

    Repeating a Local Notification after every 14 days(two weeks)?

  13. 13

    Compile lots of TeX files at the same time (or with a single command)

  14. 14

    Lots of queries on one page that take too long to execute... Can't seem to optimize them

  15. 15

    RadioButtonList not firing SelectedIndexChanged every time

  16. 16

    Getting the same answer every time

  17. 17

    Avoid n+1 queries in Django admin list view

  18. 18

    How to avoid N+1 queries in Rails "each" loops?

  19. 19

    how to avoid high CPU usage when no active queries

  20. 20

    Laravel View Composer duplicating SQL queries for every view

  21. 21

    ASP.Net Identity running multiple queries on every request

  22. 22

    Send email multiple time without repeating the email code

  23. 23

    Avoid checking the same condition every step in a loop in C++

  24. 24

    Avoid repeating the variable type: Return Type Resolver, C++11 auto, ...anything else?

  25. 25

    typescript calling a function every specific time

  26. 26

    SET working every other time Python MySQL

  27. 27

    Makefile ignores dependency every other time

  28. 28

    (Laravel) Update interface every time there is a change in the database?

  29. 29

    How to write to a new line every time in python?

ホットタグ

アーカイブ