This is an automated email from the ASF dual-hosted git repository.
zhangliang2022 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new ae57df9a1 fix: largest files with lowest number of authors dashboard
can not show (#4483)
ae57df9a1 is described below
commit ae57df9a15103871477e1002e97beefbc6edefb0
Author: abeizn <[email protected]>
AuthorDate: Wed Feb 22 16:57:40 2023 +0800
fix: largest files with lowest number of authors dashboard can not show
(#4483)
* fix: largest files with lowest number of authors dashboard can not show
* fix: add commit sha index by gorm
* fix: add commit sha index by gorm
---
backend/core/models/domainlayer/code/commit.go | 5 +-
.../20230222_add_commit_sha_index.go | 53 ++++++++++++++++++++++
backend/core/models/migrationscripts/register.go | 1 +
.../dashboards/ComponentAndFileLevelMetrics.json | 10 ++--
4 files changed, 62 insertions(+), 7 deletions(-)
diff --git a/backend/core/models/domainlayer/code/commit.go
b/backend/core/models/domainlayer/code/commit.go
index b792c9236..ad8fe1bab 100644
--- a/backend/core/models/domainlayer/code/commit.go
+++ b/backend/core/models/domainlayer/code/commit.go
@@ -18,9 +18,10 @@ limitations under the License.
package code
import (
+ "time"
+
"github.com/apache/incubator-devlake/core/models/common"
"github.com/apache/incubator-devlake/core/models/domainlayer"
- "time"
)
type Commit struct {
@@ -46,7 +47,7 @@ func (Commit) TableName() string {
type CommitFile struct {
domainlayer.DomainEntity
- CommitSha string `gorm:"type:varchar(40)"`
+ CommitSha string `gorm:"index;type:varchar(40)"`
FilePath string `gorm:"type:text"`
Additions int
Deletions int
diff --git
a/backend/core/models/migrationscripts/20230222_add_commit_sha_index.go
b/backend/core/models/migrationscripts/20230222_add_commit_sha_index.go
new file mode 100644
index 000000000..7ad079aac
--- /dev/null
+++ b/backend/core/models/migrationscripts/20230222_add_commit_sha_index.go
@@ -0,0 +1,53 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements. See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package migrationscripts
+
+import (
+ "github.com/apache/incubator-devlake/core/context"
+ "github.com/apache/incubator-devlake/core/errors"
+ "github.com/apache/incubator-devlake/core/plugin"
+ "github.com/apache/incubator-devlake/helpers/migrationhelper"
+)
+
+var _ plugin.MigrationScript = (*addCommitShaIndex)(nil)
+
+type commitFile20230222 struct {
+ CommitSha string `gorm:"index;type:varchar(40)"`
+}
+
+func (commitFile20230222) TableName() string {
+ return "commit_files"
+}
+
+type addCommitShaIndex struct{}
+
+func (script *addCommitShaIndex) Up(basicRes context.BasicRes) errors.Error {
+
+ return migrationhelper.AutoMigrateTables(
+ basicRes,
+ &commitFile20230222{},
+ )
+}
+
+func (*addCommitShaIndex) Version() uint64 {
+ return 20230222145127
+}
+
+func (*addCommitShaIndex) Name() string {
+ return "add commit_sha index for commit_files"
+}
diff --git a/backend/core/models/migrationscripts/register.go
b/backend/core/models/migrationscripts/register.go
index da0ad9d46..ca5cb8320 100644
--- a/backend/core/models/migrationscripts/register.go
+++ b/backend/core/models/migrationscripts/register.go
@@ -72,5 +72,6 @@ func All() []plugin.MigrationScript {
new(addTimeAfterToCollectorMeta20230213),
new(addCodeQuality),
new(modifyIssueStorypointToFloat64),
+ new(addCommitShaIndex),
}
}
diff --git a/grafana/dashboards/ComponentAndFileLevelMetrics.json
b/grafana/dashboards/ComponentAndFileLevelMetrics.json
index 69e1f9e5d..ab49cce0e 100644
--- a/grafana/dashboards/ComponentAndFileLevelMetrics.json
+++ b/grafana/dashboards/ComponentAndFileLevelMetrics.json
@@ -16,8 +16,8 @@
"editable": true,
"gnetId": null,
"graphTooltip": 0,
- "id": 9,
- "iteration": 1672982007817,
+ "id": 17,
+ "iteration": 1677030964408,
"links": [],
"panels": [
{
@@ -169,7 +169,7 @@
"metricColumn": "none",
"queryType": "randomWalk",
"rawQuery": true,
- "rawSql": "SELECT file_path,\n count(distinct author_name) AS
author_count,\n max(rst) AS file_total_size,max(rst)/count(distinct
author_name) as rate\nFROM commits\nJOIN \n (SELECT file_path,\n
commit_files.commit_sha,\n sum(additions) - sum(deletions) AS rst\n
FROM commit_files\n JOIN repo_commits rc\n ON commit_files.commit_sha
= rc.commit_sha\n WHERE repo_id IN ($repo_id)\n\n GROUP BY
file_path,commit_sha\n ORDER BY r [...]
+ "rawSql": "SELECT file_path,\n COUNT(DISTINCT author_name) AS
author_count,\n MAX(rst) AS file_total_size,\n MAX(rst) /
COUNT(DISTINCT author_name) AS rate\nFROM commits\nJOIN (\n SELECT
file_path,\n commit_files.commit_sha,\n SUM(additions -
deletions) AS rst\n FROM commit_files\n JOIN repo_commits rc ON
commit_files.commit_sha = rc.commit_sha\n WHERE repo_id IN ($repo_id)\n GROUP
BY file_path, commit_files.commit_sha\n) a ON a.commit_sha [...]
"refId": "A",
"select": [
[
@@ -991,7 +991,7 @@
{
"allValue": null,
"current": {
- "selected": true,
+ "selected": false,
"text": [
"All"
],
@@ -1061,5 +1061,5 @@
"timezone": "",
"title": "Component and File-level Metrics",
"uid": "KxUh7IG4z",
- "version": 3
+ "version": 4
}
\ No newline at end of file