Reduce database writes in credentials_controller specs
What does this MR do?
Refactors parts of ee/spec/controllers/admin/credentials_controller_spec.rb
to make use of existing factories to reduce unneccessary database writes in this spec file.
- Reduces database writes without sacrificing spec intent. (
User
creations is down from 12 -> 1) - Reduces total time spent in factories from ~1.2s to ~0.26s.
- Database queries reduced from 536 to 214. (60% decrease)
Queries saved: 322
FPROF Stats
Before
[TEST PROF INFO] Factories usage
Total: 34
Total top-level: 24
Total time: 1.1878s
Total uniq factories: 5
total top-level total time time per call top-level time name
12 2 0.4914s 0.0409s 0.1778s user
11 11 0.4861s 0.0442s 0.4861s admin
8 8 0.3366s 0.0421s 0.3366s personal_access_token
2 2 0.1785s 0.0892s 0.1785s personal_key
1 1 0.0089s 0.0089s 0.0089s license
After
[TEST PROF INFO] Factories usage
Total: 10
Total top-level: 10
Total time: 0.2751s
Total uniq factories: 5
total top-level total time time per call top-level time name
5 5 0.0634s 0.0127s 0.0634s personal_access_token
2 2 0.0663s 0.0331s 0.0663s personal_key
1 1 0.0082s 0.0082s 0.0082s license
1 1 0.1054s 0.1054s 0.1054s admin
1 1 0.0318s 0.0318s 0.0318s user
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Edited by Max Woolf