Skip to content

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

Availability and Testing

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

Merge request reports