Investigation: Importer - Concurrent Access to Database
Context
Currently, the importer will access certain records in a "Find or Create" pattern. While this is fine for a one-shot import against a smaller database, the Gradual migration proposal for the GitLab.com container registry includes a phase in which the import is running alongside a registry which is accessing the database and running online garbage collection.
Solution
We should replace the instances of "Find or Create" with the "Create or Find" type methods, used throughout the API handlers, which are designed for concurrent access. Additionally, we should apply the same techniques to avoid race conditions with the garbage collector as described and addressed in #300 (closed) where applicable.
There are some concerns around incrementing the primary key on insert conflicts with the current "Create or Find" approach (please see #328 (comment 532568340)). We first need to discuss this with the Database team before settling on an implementation approach.