Skip to content

Commit 2403c80

Browse files
committed
init license classifier when boot
1 parent 35f0800 commit 2403c80

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

routers/init.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ func InitWebInstalled(ctx context.Context) {
172172

173173
actions_service.Init()
174174

175+
mustInit(repo_service.InitLicenseClassifier)
176+
175177
// Finally start up the cron
176178
cron.NewContext(ctx)
177179
}

services/repository/license.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,7 @@ func ConvertLicenseName(name string) string {
6666
return name
6767
}
6868

69-
func initClassifier() error {
70-
if classifier != nil {
71-
return nil
72-
}
73-
69+
func InitLicenseClassifier() error {
7470
// threshold should be 0.84~0.86 or the test will be failed
7571
classifier = licenseclassifier.NewClassifier(.85)
7672
licenseFiles, err := options.AssetFS().ListFiles("license", true)
@@ -191,9 +187,6 @@ func detectLicense(r io.Reader) ([]string, error) {
191187
if r == nil {
192188
return nil, nil
193189
}
194-
if err := initClassifier(); err != nil {
195-
return nil, err
196-
}
197190

198191
matches, err := classifier.MatchFrom(r)
199192
if err != nil {

services/repository/license_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func Test_detectLicense(t *testing.T) {
5252
})
5353
}
5454

55-
err = initClassifier()
55+
err = InitLicenseClassifier()
5656
assert.NoError(t, err)
5757
for _, tt := range tests {
5858
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)