From b7dfefbf1c44bd15c5b4e0aa213c2c8dec6e531b Mon Sep 17 00:00:00 2001 From: "suguo.yao" Date: Mon, 17 Oct 2022 15:06:30 +0800 Subject: [PATCH] init --- README.md | 3 + go.mod | 1 + go.sum | 2 + model/domain-model.go | 8 +-- model/site-model.go | 12 ++-- service/domain-service.go | 31 ---------- service/probe-service.go | 22 +++++++- service/site-service.go | 115 +++++++++++++++++++++++++++++++++++++- 8 files changed, 149 insertions(+), 45 deletions(-) delete mode 100644 service/domain-service.go diff --git a/README.md b/README.md index 63916e8..fe56e54 100644 --- a/README.md +++ b/README.md @@ -6,5 +6,8 @@ 1. 只搜索网站根目录下的index.htm(l)内容 1. 只记录网站有title及description内容的网站,对title及description限制最大长度20和255. +### 问题 +1. URL有效字符37,按URL10个长度算,37^10=4808584372417849,天文数字 + diff --git a/go.mod b/go.mod index 8c09e11..34bca6d 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.19 require ( github.com/google/uuid v1.3.0 + golang.org/x/net v0.0.0-20221014081412-f15817d10f9b gorm.io/driver/mysql v1.4.1 gorm.io/gorm v1.24.0 gorm.io/plugin/dbresolver v1.3.0 diff --git a/go.sum b/go.sum index e5fc8a0..06c8879 100644 --- a/go.sum +++ b/go.sum @@ -7,6 +7,8 @@ github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkr github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +golang.org/x/net v0.0.0-20221014081412-f15817d10f9b h1:tvrvnPFcdzp294diPnrdZZZ8XUt2Tyj7svb7X52iDuU= +golang.org/x/net v0.0.0-20221014081412-f15817d10f9b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= gorm.io/driver/mysql v1.3.2/go.mod h1:ChK6AHbHgDCFZyJp0F+BmVGb06PSIoh9uVYKAlRbb2U= gorm.io/driver/mysql v1.4.1 h1:4InA6SOaYtt4yYpV1NF9B2kvUKe9TbvUd1iWrvxnjic= gorm.io/driver/mysql v1.4.1/go.mod h1:sSIebwZAVPiT+27jK9HIwvsqOGKx3YMPmrA3mBJR10c= diff --git a/model/domain-model.go b/model/domain-model.go index e3cd18a..1e1b4a0 100644 --- a/model/domain-model.go +++ b/model/domain-model.go @@ -5,9 +5,7 @@ import "time" type Domain struct { Root string `gorm:"type:varchar(10);primarykey"` CreatedAt time.Time - UpdatedAt time.Time - Success uint - Failure uint - Current uint8 - Status uint8 + UpdatedAt time.Time `gorm:"index"` + Success uint64 + Failure uint64 } diff --git a/model/site-model.go b/model/site-model.go index a90186c..f0c5a1a 100644 --- a/model/site-model.go +++ b/model/site-model.go @@ -3,10 +3,10 @@ package model import "time" type Site struct { - URL string `gorm:"type:varchar(255);primarykey"` - Title string `gorm:"type:varchar(30);not null;"` - Description string `gorm:"type:varchar(255);not null;"` - AccessDuration uint `gorm:"index"` - UpdatedAt time.Time `gorm:"index"` - CreatedAt time.Time + URL string `gorm:"type:varchar(255);primarykey"` + Title string `gorm:"type:varchar(30);not null;"` + Description string `gorm:"type:varchar(255);not null;"` + LinkCount uint `gorm:"index"` + UpdatedAt time.Time `gorm:"index"` + CreatedAt time.Time } diff --git a/service/domain-service.go b/service/domain-service.go deleted file mode 100644 index 1953148..0000000 --- a/service/domain-service.go +++ /dev/null @@ -1,31 +0,0 @@ -package service - -import ( - "time" - - "myschools.me/suguo/search/exceptionless" - "myschools.me/suguo/search/model" - "myschools.me/suguo/search/mysql" -) - -func domainAnalyze(domain *model.Domain) { - if domain.Status != 0 && domain.UpdatedAt.After(time.Now().Add(10*time.Minute)) { - return - } - - db, err := mysql.New() - if err != nil { - exceptionless.SubmitAppError("domainAnalyze", "mysql.New", nil, err) - return - } - - if domain.Current >= uint8(250-len(domain.Root)) { - domain.Current = 1 - } - domain.Status = 1 //置状态处理中 - if err := db.Updates(domain).Error; err != nil { - exceptionless.SubmitAppError("domainAnalyze", "mysql.Updates", nil, err) - return - } - -} diff --git a/service/probe-service.go b/service/probe-service.go index cf9dfae..118be64 100644 --- a/service/probe-service.go +++ b/service/probe-service.go @@ -1,6 +1,8 @@ package service import ( + "fmt" + "math/rand" "time" "gorm.io/gorm" @@ -20,7 +22,7 @@ func Probe() { } var domains []*model.Domain - if err := db.Find(&domains).Error; err != nil { + if err := db.Where("updated_at