@@ -21,34 +21,44 @@ def initialize_insights(apps, schema_editor):
2121 user_ids = defaultdict (set )
2222
2323 for idea_model in [Idea , MapIdea , Proposal ]:
24- for idea_object in idea_model .objects .all ():
24+ for idea_object in idea_model .objects .all ().select_related (
25+ "creator" , "module__project"
26+ ):
2527 project = idea_object .module .project
2628 insights [project ].written_ideas += 1
2729 user_ids [project ].add (idea_object .creator .id )
2830
29- for live_question in LiveQuestion .objects .all ():
31+ for live_question in LiveQuestion .objects .all (). select_related ( "module__project" ) :
3032 insights [live_question .module .project ].live_questions += 1
3133
32- for answer in Answer .objects .all ():
34+ for answer in Answer .objects .all ().select_related (
35+ "creator" ,
36+ "question__poll__module__project" ,
37+ ):
3338 project = answer .question .poll .module .project
3439 insights [project ].poll_answers += 1
3540 user_ids [project ].add (answer .creator .id )
3641
37- for vote in Vote .objects .all ():
42+ for vote in Vote .objects .all ().select_related (
43+ "creator" ,
44+ "choice__question__poll__module__project" ,
45+ ):
3846 project = vote .choice .question .poll .module .project
3947 insights [project ].poll_answers += 1
4048 user_ids [project ].add (vote .creator .id )
4149
42- for comment in Comment .objects .exclude (project = None ):
50+ for comment in Comment .objects .exclude (project = None ).select_related (
51+ "project" , "creator"
52+ ):
4353 project = comment .project
4454 insights [project ].comments += 1
4555 user_ids [project ].add (comment .creator .id )
4656
47- for like in Like .objects .all ():
57+ for like in Like .objects .all (). select_related ( "livequestion__module__project" ) :
4858 project = like .livequestion .module .project
4959 insights [project ].ratings += 1
5060
51- for rating in Rating .objects .all ():
61+ for rating in Rating .objects .all (). select_related ( "creator" , "content_type" ) :
5262 model_name = rating .content_type .model
5363 content_model = apps .get_model (
5464 app_label = rating .content_type .app_label ,
0 commit comments