diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2018-06-06 13:10:59 +0200 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2018-08-01 18:58:29 +0200 |
commit | 79a5d76801a45696db629e1f543f2e1d6fa4784f (patch) | |
tree | 2c494eee7f3c26bb450f6f1ee3c6152ac4fe7666 /app/models/repository.rb | |
parent | f175014067c38f577646d101cc8d32212d582148 (diff) | |
download | gitlab-ce-79a5d76801a45696db629e1f543f2e1d6fa4784f.tar.gz |
Add repository languages for projects
Our friends at GitHub show the programming languages for a long time,
and inspired by that this commit means to create about the same
functionality.
Language detection is done through Linguist, as before, where the
difference is that we cache the result in the database. Also, Gitaly can
incrementaly scan a repository. This is done through a shell out, which
creates overhead of about 3s each run. For now this won't be improved.
Scans are triggered by pushed to the default branch, usually `master`.
However, one exception to this rule the charts page. If we're requesting
this expensive data anyway, we just cache it in the database.
Edge cases where there is no repository, or its empty are caught in the
Repository model. This makes use of Redis caching, which is probably
already loaded.
The added model is called RepositoryLanguage, which will make it harder
if/when GitLab supports multiple repositories per project. However, for
now I think this shouldn't be a concern. Also, Language could be
confused with the i18n languages and felt like the current name was
suiteable too.
Design of the Project#Show page is done with help from @dimitrieh. This
change is not visible to the end user unless detections are done.
Diffstat (limited to 'app/models/repository.rb')
-rw-r--r-- | app/models/repository.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index 50f42be661b..9a6281bc1f7 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -235,6 +235,12 @@ class Repository false end + def languages + return [] if empty? + + raw_repository.languages(root_ref) + end + # Makes sure a commit is kept around when Git garbage collection runs. # Git GC will delete commits from the repository that are no longer in any # branches or tags, but we want to keep some of these commits around, for @@ -432,6 +438,8 @@ class Repository # Runs code after a repository has been forked/imported. def after_import expire_content_cache + + DetectRepositoryLanguagesWorker.perform_async(project.id, project.owner.id) end # Runs code after a new commit has been pushed. |