Skip to content

Commit

Permalink
manual gc every crawl
Browse files Browse the repository at this point in the history
  • Loading branch information
zu1k committed Sep 5, 2020
1 parent 5b59998 commit f2275c7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
3 changes: 1 addition & 2 deletions internal/app/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import (
"sync"
"time"

"github.com/zu1k/proxypool/internal/database"

"github.com/zu1k/proxypool/internal/cache"
"github.com/zu1k/proxypool/internal/database"
"github.com/zu1k/proxypool/pkg/provider"
"github.com/zu1k/proxypool/pkg/proxy"
)
Expand Down
4 changes: 4 additions & 0 deletions internal/cron/cron.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cron

import (
"runtime"

"github.com/jasonlvhit/gocron"
"github.com/zu1k/proxypool/internal/app"
)
Expand All @@ -13,4 +15,6 @@ func Cron() {
func crawlTask() {
_ = app.InitConfigAndGetters("")
app.CrawlGo()
app.Getters = nil
runtime.GC()
}
5 changes: 4 additions & 1 deletion internal/database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)

var DB *gorm.DB
Expand All @@ -20,7 +21,9 @@ func connect() (err error) {
if url := os.Getenv("DATABASE_URL"); url != "" {
dsn = url
}
DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{})
DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{
Logger: logger.Default.LogMode(logger.Silent),
})
if err == nil {
fmt.Println("DB connect success: ", DB.Name())
}
Expand Down
3 changes: 3 additions & 0 deletions internal/database/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func InitTables() {
}

func SaveProxyList(pl proxy.ProxyList) {
if DB == nil {
return
}
proxies := make([]Proxy, pl.Len())
for i, p := range pl {
proxies[i] = Proxy{
Expand Down

0 comments on commit f2275c7

Please sign in to comment.