diff --git a/site_blocked.go b/site_blocked.go index 48299b9..9f6adb0 100644 --- a/site_blocked.go +++ b/site_blocked.go @@ -7,6 +7,7 @@ var blockedDomainList = []string{ "fbcdn.net", "facebook.com", "plus.google.com", + "plusone.google.com", "t.co", "twimg.com", "twitpic.com", diff --git a/sitestat.go b/sitestat.go index 8202959..99dd256 100644 --- a/sitestat.go +++ b/sitestat.go @@ -78,7 +78,8 @@ const siteStaleThreshold = 15 * 24 * time.Hour // shouldDrop returns true if the a VisitCnt is not visited for a long time // (several days) or is specified by user. func (vc *VisitCnt) shouldDrop() bool { - return vc.userSpecified() || time.Now().Sub(time.Time(vc.Recent)) > siteStaleThreshold + return vc.userSpecified() || time.Now().Sub(time.Time(vc.Recent)) > siteStaleThreshold || + (vc.Blocked == 0 && vc.Direct == 0) } const tmpBlockedTimeout = 2 * time.Minute @@ -113,6 +114,7 @@ func (vc *VisitCnt) OnceBlocked() bool { } func (vc *VisitCnt) tempBlocked() { + vc.BlockedVisit() // first blocked visit, then set it as temp blocked vc.blockedOn = time.Now() } @@ -151,7 +153,7 @@ func (vc *VisitCnt) DirectVisit() { } func (vc *VisitCnt) BlockedVisit() { - if vc.userSpecified() && !vc.AsTempBlocked() { + if vc.userSpecified() || vc.AsTempBlocked() { return } vc.visit(&vc.Blocked) diff --git a/sitestat_test.go b/sitestat_test.go index 5807e78..28b4f22 100644 --- a/sitestat_test.go +++ b/sitestat_test.go @@ -80,6 +80,11 @@ func TestSiteStatLoadStore(t *testing.T) { if !si.AsBlocked() || !si.AlwaysBlocked() { t.Error("builtin site twitter.com should use blocked access") } + plus, _ := ParseRequestURI("plus.google.com") + si = ld.GetVisitCnt(plus) + if !si.AsBlocked() || !si.AlwaysBlocked() { + t.Error("builtin site plus.google.com should use blocked access") + } if len(ld.GetDirectList()) == 0 { t.Error("builtin site should appear in direct site list") } @@ -136,14 +141,17 @@ func TestSiteStatVisitCnt(t *testing.T) { if !si.AsTempBlocked() { t.Error("should be blocked for 2 minutes after blocked visit") } - si.BlockedVisit() + if si.Blocked != 1 { // temp blocked should set blocked count to 1 + t.Errorf("blocked cnt for %s not correct, should be 1, got: %d\n", g4.Host, vc.Blocked) + } + si.BlockedVisit() // these should not update visit count si.BlockedVisit() vc = ss.get(g4.Host) if vc == nil { t.Fatal("no VisitCnt for ", g4.Host) } - if vc.Blocked != 2 { - t.Errorf("blocked cnt for %s not correct, should be 2, got: %d\n", g4.Host, vc.Blocked) + if vc.Blocked != 1 { + t.Errorf("blocked cnt after temp blocked should not change, %s not correct, should be 1, got: %d\n", g4.Host, vc.Blocked) } if vc.Direct != 0 { t.Errorf("direct cnt for %s not correct, should be 0, got: %d\n", g4.Host, vc.Direct)