mirror of
https://github.com/not-kennethreitz/convore.json.git
synced 2026-06-21 15:40:58 +00:00
1 line
4.3 KiB
JSON
1 line
4.3 KiB
JSON
[{"user_id": 5045, "stars": [], "topic_id": 21584, "date_created": 1303889029.4649439, "message": "Hi. I have read the Django documentation about \"select_related\", but I don't really understand when it is convenient to use it. Does someone know a good guide about how and, more important, when (or when not) to use \"select_related\"?", "group_id": 81, "id": 822972}, {"user_id": 26888, "stars": [], "topic_id": 21584, "date_created": 1303896243.9705279, "message": "However, the general idea is when you get an object from the database and you know you will use a foreign key, you should really consider it", "group_id": 81, "id": 823812}, {"user_id": 26888, "stars": [], "topic_id": 21584, "date_created": 1303896188.173393, "message": "I am not sure there's a guide for that. It depends a lot on your application", "group_id": 81, "id": 823799}, {"user_id": 5045, "stars": [], "topic_id": 21584, "date_created": 1303897057.032115, "message": "Ok, thanks. I guess that I should try it then :)", "group_id": 81, "id": 823884}, {"user_id": 5045, "stars": [], "topic_id": 21584, "date_created": 1303896540.9688671, "message": "So I guess that select_related parameters depend on which foreign_keys you want to follow. Am I right?", "group_id": 81, "id": 823843}, {"user_id": 26888, "stars": [], "topic_id": 21584, "date_created": 1303896597.0588801, "message": "Indeed, you can and should tell the select_related what relation you want to follow", "group_id": 81, "id": 823846}, {"user_id": 26888, "stars": [], "topic_id": 21584, "date_created": 1303896339.0036349, "message": "For example, if you have a Car model with foreign key to a Manufacturer and you know you will need Manufacturer informations it is a good idea to use the select_related", "group_id": 81, "id": 823828}, {"user_id": 26888, "stars": [{"date_created": 1303939215.980788, "user_id": 141}], "topic_id": 21584, "date_created": 1303896387.5841589, "message": "Doing car.manufacturer will get you 2 DB calls. One for car, one for manufacturer while select related grabs both at once.", "group_id": 81, "id": 823829}, {"user_id": 26888, "stars": [], "topic_id": 21584, "date_created": 1303896478.4269941, "message": "It is very powerfull on querysets. If you get a list of cars, doins car.manufacturer on each will give N+1 DB calls while select_related will reduce it to one :)", "group_id": 81, "id": 823839}, {"user_id": 26888, "stars": [{"date_created": 1303938189.799983, "user_id": 13912}], "topic_id": 21584, "date_created": 1303897195.484076, "message": "I would advice to use django debug toolbar to see the database request so that you can see how select_related helps you ;)", "group_id": 81, "id": 823900}, {"user_id": 5045, "stars": [], "topic_id": 21584, "date_created": 1303897274.1222539, "message": "That will be easy, since I'm already using it :)", "group_id": 81, "id": 823909}, {"user_id": 13912, "stars": [], "topic_id": 21584, "date_created": 1303938628.920922, "message": "in such a simple scenario even forgetting to do this is much faster than hitting the database with 10 queries if you didn't use select related", "group_id": 81, "id": 832712}, {"user_id": 13912, "stars": [], "topic_id": 21584, "date_created": 1303938410.135169, "message": "if you have a Book model that has foreign keys to a Genre model and an Author model", "group_id": 81, "id": 832656}, {"user_id": 13912, "stars": [], "topic_id": 21584, "date_created": 1303938566.0742631, "message": "in SQL this translates to one join instead of two which is generally faster", "group_id": 81, "id": 832702}, {"user_id": 13912, "stars": [], "topic_id": 21584, "date_created": 1303938521.1128261, "message": "Book.objects.select_related('genre')...", "group_id": 81, "id": 832692}, {"user_id": 13912, "stars": [], "topic_id": 21584, "date_created": 1303938324.961566, "message": "another thing worth noting with select related is when you should pass parameters to it", "group_id": 81, "id": 832631}, {"user_id": 13912, "stars": [], "topic_id": 21584, "date_created": 1303938445.1497409, "message": "and you only want to display the Genre name for the book but don't want to display any info for the author you should use", "group_id": 81, "id": 832668}, {"user_id": 13912, "stars": [], "topic_id": 21584, "date_created": 1303938722.415194, "message": "it also supports more complex usage scenarios, limiting the depth of foreign key \"links\" that are followed etc.", "group_id": 81, "id": 832730}] |