Revert "gosrc: include package updated time in the request header."
The current process to fetch GitHub packages check the reference first,
which is the API call I use in the change for timestamp check. It turns
out the last modified timestamp returned can be older than the most
recent commit.
This reverts commit 3abf7616294048af14f0c5e99fc63ed7d8277bc7.
Change-Id: I55d38f55ee118ed6069dd9b3231858cebcf95281
Reviewed-on: https://go-review.googlesource.com/22700
Reviewed-by: Andrew Gerrand <adg@golang.org>
diff --git a/doc/get.go b/doc/get.go
index 977e3fb..611bfd0 100644
--- a/doc/get.go
+++ b/doc/get.go
@@ -12,10 +12,9 @@
"go/doc"
"net/http"
"strings"
- "time"
)
-func Get(client *http.Client, importPath string, etag string, updated time.Time) (*Package, error) {
+func Get(client *http.Client, importPath string, etag string) (*Package, error) {
const versionPrefix = PackageVersion + "-"
@@ -25,7 +24,7 @@
etag = ""
}
- dir, err := gosrc.Get(client, importPath, etag, updated)
+ dir, err := gosrc.Get(client, importPath, etag)
if err != nil {
return nil, err
}
diff --git a/doc/print.go b/doc/print.go
index 6950c79..b199bbb 100644
--- a/doc/print.go
+++ b/doc/print.go
@@ -41,7 +41,8 @@
if *local {
gosrc.SetLocalDevMode(os.Getenv("GOPATH"))
}
- pdoc, err = doc.Get(http.DefaultClient, path, *etag, pdoc.Updated)
+ pdoc, err = doc.Get(http.DefaultClient, path, *etag)
+ //}
if err != nil {
log.Fatal(err)
}
diff --git a/gddo-server/crawl.go b/gddo-server/crawl.go
index 23516c3..fb23fa7 100644
--- a/gddo-server/crawl.go
+++ b/gddo-server/crawl.go
@@ -53,11 +53,7 @@
err = gosrc.NotFoundError{Message: "testdata."}
} else {
var pdocNew *doc.Package
- updated := time.Time{}
- if pdoc != nil {
- updated = pdoc.Updated
- }
- pdocNew, err = doc.Get(httpClient, importPath, etag, updated)
+ pdocNew, err = doc.Get(httpClient, importPath, etag)
message = append(message, "fetch:", int64(time.Since(start)/time.Millisecond))
if err == nil && pdocNew.Name == "" && !hasSubdirs {
for _, e := range pdocNew.Errors {
@@ -88,11 +84,6 @@
return pdoc, nil
case err == gosrc.ErrNotModified:
message = append(message, "touch")
- // If the package is not modified, set the updated time
- pdoc.Updated = time.Now().UTC()
- if err := db.Put(pdoc, nextCrawl, false); err != nil {
- log.Printf("ERROR db.Put(%q): %v", importPath, err)
- }
if err := db.SetNextCrawlEtag(pdoc.ProjectRoot, pdoc.Etag, nextCrawl); err != nil {
log.Printf("ERROR db.SetNextCrawlEtag(%q): %v", importPath, err)
}
diff --git a/gddo-server/main.go b/gddo-server/main.go
index 77785a7..5cb3ed5 100644
--- a/gddo-server/main.go
+++ b/gddo-server/main.go
@@ -302,9 +302,7 @@
log.Printf("ERROR db.IncrementPopularScore(%s): %v", pdoc.ImportPath, err)
}
}
- if gceLogger != nil {
- gceLogger.LogEvent(resp, req, nil)
- }
+ gceLogger.LogEvent(resp, req, nil)
template := "dir"
switch {
@@ -419,13 +417,13 @@
func serveRefresh(resp http.ResponseWriter, req *http.Request) error {
importPath := req.Form.Get("path")
- pdoc, pkgs, _, err := db.Get(importPath)
+ _, pkgs, _, err := db.Get(importPath)
if err != nil {
return err
}
c := make(chan error, 1)
go func() {
- _, err := crawlDoc("rfrsh", importPath, pdoc, len(pkgs) > 0, time.Time{})
+ _, err := crawlDoc("rfrsh", importPath, nil, len(pkgs) > 0, time.Time{})
c <- err
}()
select {
diff --git a/gosrc/bitbucket.go b/gosrc/bitbucket.go
index 219e87d..437349c 100644
--- a/gosrc/bitbucket.go
+++ b/gosrc/bitbucket.go
@@ -32,7 +32,7 @@
} `json:"fork_of"`
}
-func getBitbucketDir(client *http.Client, match map[string]string, savedEtag string, updated time.Time) (*Directory, error) {
+func getBitbucketDir(client *http.Client, match map[string]string, savedEtag string) (*Directory, error) {
var repo *bitbucketRepo
c := &httpClient{client: client}
diff --git a/gosrc/github.go b/gosrc/github.go
index 32e5e84..5ae969f 100644
--- a/gosrc/github.go
+++ b/gosrc/github.go
@@ -48,17 +48,9 @@
return &RemoteError{resp.Request.URL.Host, fmt.Errorf("%d: (%s)", resp.StatusCode, resp.Request.URL.String())}
}
-func getGitHubDir(client *http.Client, match map[string]string, savedEtag string, updated time.Time) (*Directory, error) {
+func getGitHubDir(client *http.Client, match map[string]string, savedEtag string) (*Directory, error) {
- c := &httpClient{
- client: client,
- errFn: gitHubError,
- }
- if !updated.IsZero() {
- // http.TimeFormat is used since GitHub API will count against our rate limit
- // if we use any timezone other than "GMT".
- c.header = http.Header{"If-Modified-Since": {updated.Format(http.TimeFormat)}}
- }
+ c := &httpClient{client: client, errFn: gitHubError}
type refJSON struct {
Object struct {
@@ -73,11 +65,6 @@
resp, err := c.getJSON(expand("https://api.github.com/repos/{owner}/{repo}/git/refs", match), &refs)
if err != nil {
- if resp != nil {
- if last, err := time.Parse(http.TimeFormat, resp.Header.Get("Last-Modified")); err == nil && last.Before(updated) {
- return nil, ErrNotModified
- }
- }
return nil, err
}
@@ -297,14 +284,8 @@
}, nil
}
-func getGistDir(client *http.Client, match map[string]string, savedEtag string, updated time.Time) (*Directory, error) {
- c := &httpClient{
- client: client,
- errFn: gitHubError,
- }
- if !updated.IsZero() {
- c.header = http.Header{"If-Modified-Since": {updated.Format(http.TimeFormat)}}
- }
+func getGistDir(client *http.Client, match map[string]string, savedEtag string) (*Directory, error) {
+ c := &httpClient{client: client, errFn: gitHubError}
var gist struct {
Files map[string]struct {
diff --git a/gosrc/google.go b/gosrc/google.go
index d52d403..1a47b59 100644
--- a/gosrc/google.go
+++ b/gosrc/google.go
@@ -12,7 +12,6 @@
"net/url"
"regexp"
"strings"
- "time"
)
func init() {
@@ -49,7 +48,7 @@
return c.err(resp)
}
-func getGoogleDir(client *http.Client, match map[string]string, savedEtag string, updated time.Time) (*Directory, error) {
+func getGoogleDir(client *http.Client, match map[string]string, savedEtag string) (*Directory, error) {
setupGoogleMatch(match)
c := &httpClient{client: client}
diff --git a/gosrc/gosrc.go b/gosrc/gosrc.go
index 7953ea8..1505737 100644
--- a/gosrc/gosrc.go
+++ b/gosrc/gosrc.go
@@ -16,7 +16,6 @@
"path"
"regexp"
"strings"
- "time"
)
// File represents a file.
@@ -115,7 +114,7 @@
type service struct {
pattern *regexp.Regexp
prefix string
- get func(*http.Client, map[string]string, string, time.Time) (*Directory, error)
+ get func(*http.Client, map[string]string, string) (*Directory, error)
getPresentation func(*http.Client, map[string]string) (*Presentation, error)
getProject func(*http.Client, map[string]string) (*Project, error)
}
@@ -305,7 +304,7 @@
// getVCSDirFn is called by getDynamic to fetch source using VCS commands. The
// default value here does nothing. If the code is not built for App Engine,
// then getvCSDirFn is set getVCSDir, the function that actually does the work.
-var getVCSDirFn = func(client *http.Client, m map[string]string, etag string, updated time.Time) (*Directory, error) {
+var getVCSDirFn = func(client *http.Client, m map[string]string, etag string) (*Directory, error) {
return nil, errNoMatch
}
@@ -341,7 +340,7 @@
dirName := importPath[len(im.projectRoot):]
resolvedPath := repo + dirName
- dir, err := getStatic(client, resolvedPath, etag, time.Time{})
+ dir, err := getStatic(client, resolvedPath, etag)
if err == errNoMatch {
resolvedPath = repo + "." + im.vcs + dirName
match := map[string]string{
@@ -352,7 +351,7 @@
"scheme": proto,
"vcs": im.vcs,
}
- dir, err = getVCSDirFn(client, match, etag, time.Time{})
+ dir, err = getVCSDirFn(client, match, etag)
}
if err != nil || dir == nil {
return nil, err
@@ -407,7 +406,7 @@
// getStatic gets a diretory from a statically known service. getStatic
// returns errNoMatch if the import path is not recognized.
-func getStatic(client *http.Client, importPath, etag string, updated time.Time) (*Directory, error) {
+func getStatic(client *http.Client, importPath, etag string) (*Directory, error) {
for _, s := range services {
if s.get == nil {
continue
@@ -417,7 +416,7 @@
return nil, err
}
if match != nil {
- dir, err := s.get(client, match, etag, updated)
+ dir, err := s.get(client, match, etag)
if dir != nil {
dir.ImportPath = importPath
dir.ResolvedPath = importPath
@@ -428,14 +427,14 @@
return nil, errNoMatch
}
-func Get(client *http.Client, importPath string, etag string, updated time.Time) (dir *Directory, err error) {
+func Get(client *http.Client, importPath string, etag string) (dir *Directory, err error) {
switch {
case localPath != "":
dir, err = getLocal(importPath)
case IsGoRepoPath(importPath):
dir, err = getStandardDir(client, importPath, etag)
case IsValidRemotePath(importPath):
- dir, err = getStatic(client, importPath, etag, updated)
+ dir, err = getStatic(client, importPath, etag)
if err == errNoMatch {
dir, err = getDynamic(client, importPath, etag)
}
diff --git a/gosrc/launchpad.go b/gosrc/launchpad.go
index fe3586b..5cda037 100644
--- a/gosrc/launchpad.go
+++ b/gosrc/launchpad.go
@@ -18,7 +18,6 @@
"regexp"
"sort"
"strings"
- "time"
)
func init() {
@@ -42,7 +41,7 @@
copy(p[j*md5.Size:], temp[:])
}
-func getLaunchpadDir(client *http.Client, match map[string]string, savedEtag string, updated time.Time) (*Directory, error) {
+func getLaunchpadDir(client *http.Client, match map[string]string, savedEtag string) (*Directory, error) {
c := &httpClient{client: client}
if match["project"] != "" && match["series"] != "" {
diff --git a/gosrc/vcs.go b/gosrc/vcs.go
index e2750f0..6fbb545 100644
--- a/gosrc/vcs.go
+++ b/gosrc/vcs.go
@@ -245,7 +245,7 @@
return "", NotFoundError{Message: "Last changed revision not found"}
}
-func getVCSDir(client *http.Client, match map[string]string, etagSaved string, updated time.Time) (*Directory, error) {
+func getVCSDir(client *http.Client, match map[string]string, etagSaved string) (*Directory, error) {
cmd := vcsCmds[match["vcs"]]
if cmd == nil {
return nil, NotFoundError{Message: expand("VCS not supported: {vcs}", match)}