File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -163,4 +163,48 @@ class APIModelsUserGroupTestCase extends TestCase {
163163 },
164164 );
165165 }
166+
167+ /**
168+ * Ensures UserGroups remain readable even when many users are assigned to a group. This tests for performance
169+ * issues identified in GitHub issue #779.
170+ */
171+ public function test_read_performance_with_many_members (): void
172+ {
173+ # Mock creating many users by direct config assignment
174+ foreach (range (1 , 1000 ) as $ idx ) {
175+ global $ config ;
176+ $ config ['system ' ]['user ' ][] = [
177+ 'name ' => "testuser $ idx " ,
178+ 'uid ' => 3000 + $ idx ,
179+ ];
180+ }
181+
182+ # Create a UserGroup with many members
183+ $ user_group = new UserGroup (
184+ name: 'biggroup ' ,
185+ scope: 'local ' ,
186+ member: [],
187+ );
188+ $ user_group ->create ();
189+
190+ # Perform an update that maps all created users to our group and track its time
191+ $ start_time = time ();
192+ $ user_group ->member ->value = array_map (fn ($ i ) => "testuser $ i " , range (1 , 1000 ));
193+ $ user_group ->update ();
194+ $ end_time = time ();
195+ $ duration = $ end_time - $ start_time ;
196+
197+ # Ensure the update took less than 10 seconds
198+ $ this ->assert_is_less_than ($ duration , 5 );
199+
200+ # Ensure we can read all user groups within 10 seconds
201+ $ start_time = time ();
202+ UserGroup::read_all ();
203+ $ end_time = time ();
204+ $ duration = $ end_time - $ start_time ;
205+ $ this ->assert_is_less_than ($ duration , 5 );
206+
207+ # Clean up the user group
208+ $ user_group ->delete ();
209+ }
166210}
You can’t perform that action at this time.
0 commit comments