@@ -205,7 +205,44 @@ def test_modify_component_after_publish(self):
205
205
assert authoring_api .contains_unpublished_changes (unit ) == False # No longer contains unpublished changes
206
206
207
207
208
- # Test query count of contains_unpublished_changes()
208
+ def test_query_count_of_contains_unpublished_changes (self ):
209
+ """
210
+ Checking for unpublished changes in a unit should require a fixed number
211
+ of queries, not get more expensive as the unit gets larger.
212
+ """
213
+ unit , unit_version = authoring_api .create_unit_and_version (
214
+ learning_package_id = self .learning_package .id ,
215
+ key = f"unit:key" ,
216
+ title = "Unit" ,
217
+ created = self .now ,
218
+ created_by = None ,
219
+ )
220
+ # Add 100 components (unpinned)
221
+ component_count = 100
222
+ publishable_entities_pks = []
223
+ for i in range (0 , component_count ):
224
+ component , _version = authoring_api .create_component_and_version (
225
+ self .learning_package .id ,
226
+ component_type = self .problem_type ,
227
+ local_key = f"Query Counting { i } " ,
228
+ title = f"Querying Counting Problem { i } " ,
229
+ created = self .now ,
230
+ )
231
+ publishable_entities_pks .append (component .publishable_entity_id )
232
+ authoring_api .create_next_unit_version (
233
+ unit = unit ,
234
+ title = unit_version .title ,
235
+ publishable_entities_pks = publishable_entities_pks ,
236
+ draft_version_pks = [None ] * component_count ,
237
+ published_version_pks = [None ] * component_count , # FIXME: why do we specify this?
238
+ created = self .now ,
239
+ )
240
+ authoring_api .publish_all_drafts (self .learning_package .id )
241
+ unit .refresh_from_db ()
242
+ with self .assertNumQueries (3 ):
243
+ assert authoring_api .contains_unpublished_changes (unit ) == False
244
+
245
+ # Test that pinned components with changes don't show up as "contains unpublished changes"
209
246
# Test that only components can be added to units
210
247
# Test that components must be in the same learning package
211
248
# Test that _version_pks=[] arguments must be related to publishable_entities_pks
0 commit comments