Cache license/feature-flag queries during import
Problem to solve
It seems that we over and over access license table to check if features are licensed. This results in additional SQL query, but also additional memory pressure due to AR initialisation. We should figure out a way to ensure that this is cached in memory and preserved for time of running import.
For some relations I counted around 30 additional queries against database FOR SINGLE RELATION.
D, [2019-12-09T17:09:39.011087 #64] DEBUG -- : (3.4ms) COMMIT
D, [2019-12-09T17:09:39.011157 #64] DEBUG -- : ↳ lib/gitlab/import_export/project_tree_restorer.rb:103
D, [2019-12-09T17:09:39.012332 #64] DEBUG -- : License Load (0.3ms) SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT $1 [["LIMIT", 1]]
D, [2019-12-09T17:09:39.012398 #64] DEBUG -- : ↳ ee/app/models/license.rb:257
D, [2019-12-09T17:09:39.013968 #64] DEBUG -- : License Load (0.3ms) SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT $1 [["LIMIT", 1]]
D, [2019-12-09T17:09:39.014033 #64] DEBUG -- : ↳ ee/app/models/license.rb:257
D, [2019-12-09T17:09:39.014965 #64] DEBUG -- : License Load (0.3ms) SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT $1 [["LIMIT", 1]]
D, [2019-12-09T17:09:39.015024 #64] DEBUG -- : ↳ ee/app/models/license.rb:257
D, [2019-12-09T17:09:39.015963 #64] DEBUG -- : License Load (0.3ms) SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT $1 [["LIMIT", 1]]
D, [2019-12-09T17:09:39.016027 #64] DEBUG -- : ↳ ee/app/models/license.rb:257
D, [2019-12-09T17:09:39.016861 #64] DEBUG -- : License Load (0.2ms) SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT $1 [["LIMIT", 1]]
D, [2019-12-09T17:09:39.016938 #64] DEBUG -- : ↳ ee/app/models/license.rb:257
D, [2019-12-09T17:09:39.017803 #64] DEBUG -- : License Load (0.2ms) SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT $1 [["LIMIT", 1]]
D, [2019-12-09T17:09:39.017860 #64] DEBUG -- : ↳ ee/app/models/license.rb:257
D, [2019-12-09T17:09:39.018900 #64] DEBUG -- : License Load (0.3ms) SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT $1 [["LIMIT", 1]]
D, [2019-12-09T17:09:39.018961 #64] DEBUG -- : ↳ ee/app/models/license.rb:257
D, [2019-12-09T17:09:39.019870 #64] DEBUG -- : License Load (0.3ms) SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT $1 [["LIMIT", 1]]
D, [2019-12-09T17:09:39.019932 #64] DEBUG -- : ↳ ee/app/models/license.rb:257
D, [2019-12-09T17:09:39.020838 #64] DEBUG -- : License Load (0.3ms) SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT $1 [["LIMIT", 1]]
D, [2019-12-09T17:09:39.020915 #64] DEBUG -- : ↳ ee/app/models/license.rb:257
D, [2019-12-09T17:09:39.021810 #64] DEBUG -- : License Load (0.3ms) SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT $1 [["LIMIT", 1]]
D, [2019-12-09T17:09:39.021871 #64] DEBUG -- : ↳ ee/app/models/license.rb:257
D, [2019-12-09T17:09:39.022736 #64] DEBUG -- : License Load (0.3ms) SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT $1 [["LIMIT", 1]]
D, [2019-12-09T17:09:39.022793 #64] DEBUG -- : ↳ ee/app/models/license.rb:257
D, [2019-12-09T17:09:39.023702 #64] DEBUG -- : License Load (0.3ms) SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id" DESC LIMIT $1 [["LIMIT", 1]]
D, [2019-12-09T17:09:39.023758 #64] DEBUG -- : ↳ ee/app/models/license.rb:257
D, [2019-12-09T17:09:39.231718 #64] DEBUG -- : (0.3ms) BEGIN
D, [2019-12-09T17:09:39.231826 #64] DEBUG -- : ↳ lib/gitlab/import_export/group_project_object_builder.rb:16
D, [2019-12-09T17:09:39.232544 #64] DEBUG -- : Label Load (0.3ms) SELECT "labels".* FROM "labels" WHERE "labels"."project_id" = 43 AND "labels"."title" = 'XXX' ORDER BY "labels"."title" ASC LIMIT $1 [["LIMIT", 1]]
Intended users
Edited by Craig Gomes