-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(github): add index to tool layer table _tool_github_jobs (#7932)
- Loading branch information
Showing
3 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
backend/plugins/github/models/migrationscripts/20240821_add_index_to_tool_github_jobs.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
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" | ||
"net/url" | ||
) | ||
|
||
var _ plugin.MigrationScript = (*addIndexToGithubJobs)(nil) | ||
|
||
type addIndexToGithubJobs struct{} | ||
|
||
func (script *addIndexToGithubJobs) Up(basicRes context.BasicRes) errors.Error { | ||
db := basicRes.GetDal() | ||
dbUrl := basicRes.GetConfig("DB_URL") | ||
if dbUrl == "" { | ||
return errors.BadInput.New("DB_URL is required") | ||
} | ||
u, errParse := url.Parse(dbUrl) | ||
if errParse != nil { | ||
return errors.Convert(errParse) | ||
} | ||
if u.Scheme == "mysql" { | ||
sql := "ALTER TABLE `_tool_github_jobs` ADD INDEX `idx_repo_id_connection_id` (`repo_id`, `connection_id`)" | ||
if err := db.Exec(sql); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (*addIndexToGithubJobs) Version() uint64 { | ||
return 20240821160000 | ||
} | ||
|
||
func (*addIndexToGithubJobs) Name() string { | ||
return "add index to _tool_github_jobs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
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 tasks | ||
|
||
import ( | ||
"fmt" | ||
"github.com/apache/incubator-devlake/core/models/domainlayer/didgen" | ||
"github.com/apache/incubator-devlake/core/plugin" | ||
mockplugin "github.com/apache/incubator-devlake/mocks/core/plugin" | ||
"github.com/apache/incubator-devlake/plugins/github/models" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func GenJobIDWithReflect(jobIdGen *didgen.DomainIdGenerator) { | ||
connectionId := uint64(1) | ||
runId := 1 | ||
lineId := 1 | ||
jobIdGen.Generate(connectionId, runId, lineId) | ||
} | ||
|
||
func GenJobID() { | ||
connectionId := uint64(1) | ||
runId := 1 | ||
lineId := 1 | ||
fmt.Sprintf("GithubJob:%d:%d:%d", connectionId, runId, lineId) | ||
} | ||
|
||
func BenchmarkGenJobIDWithReflect(b *testing.B) { | ||
mockMeta := mockplugin.NewPluginMeta(b) | ||
mockMeta.On("RootPkgPath").Return("github.com/apache/incubator-devlake/plugins/github") | ||
mockMeta.On("Name").Return("github").Maybe() | ||
err := plugin.RegisterPlugin("github", mockMeta) | ||
assert.NoError(b, err) | ||
|
||
jobIdGen := didgen.NewDomainIdGenerator(&models.GithubJob{}) | ||
b.StartTimer() | ||
for i := 0; i < b.N; i++ { | ||
GenJobIDWithReflect(jobIdGen) | ||
} | ||
b.StopTimer() | ||
//BenchmarkGenJobIDWithReflect-8 5611773 208.9 ns/op | ||
} | ||
|
||
func BenchmarkGenJobID(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
GenJobID() | ||
} | ||
//BenchmarkGenJobID-8 11078593 99.43 ns/op | ||
} |