diff --git a/database/database.go b/database/database.go
index 1a82e02..9f721a5 100644
--- a/database/database.go
+++ b/database/database.go
@@ -85,7 +85,6 @@ var (
RedisServer = "redis://127.0.0.1:6379" // URL of Redis server
RedisIdleTimeout = 250 * time.Second // Close Redis connections after remaining idle for this duration.
RedisLog = false // Log database commands
- GAESearch = false // Use GAE Search API in the search function.
)
func dialDb() (c redis.Conn, err error) {
@@ -274,28 +273,26 @@ func (db *Database) Put(pdoc *doc.Package, nextCrawl time.Time, hide bool) error
return err
}
- if GAESearch {
- id, n, err := pkgIDAndImportCount(c, pdoc.ImportPath)
- if err != nil {
- return err
+ id, n, err := pkgIDAndImportCount(c, pdoc.ImportPath)
+ if err != nil {
+ return err
+ }
+ ctx := bgCtx()
+
+ if score > 0 {
+ if err := PutIndex(ctx, pdoc, id, score, n); err != nil {
+ log.Printf("Cannot put %q in index: %v", pdoc.ImportPath, err)
}
- ctx := bgCtx()
- if score > 0 {
- if err := PutIndex(ctx, pdoc, id, score, n); err != nil {
- log.Printf("Cannot put %q in index: %v", pdoc.ImportPath, err)
- }
-
- if old != nil {
- if err := updateImportsIndex(c, ctx, old, pdoc); err != nil {
- return err
- }
- }
- } else {
- if err := deleteIndex(ctx, id); err != nil {
+ if old != nil {
+ if err := updateImportsIndex(c, ctx, old, pdoc); err != nil {
return err
}
}
+ } else {
+ if err := deleteIndex(ctx, id); err != nil {
+ return err
+ }
}
if nextCrawl.IsZero() {
@@ -607,21 +604,19 @@ func (db *Database) Delete(path string) error {
c := db.Pool.Get()
defer c.Close()
- if GAESearch {
- ctx := bgCtx()
- id, err := redis.String(c.Do("HGET", "ids", path))
- if err == redis.ErrNil {
- return nil
- }
- if err != nil {
- return err
- }
- if err := deleteIndex(ctx, id); err != nil {
- return err
- }
+ ctx := bgCtx()
+ id, err := redis.String(c.Do("HGET", "ids", path))
+ if err == redis.ErrNil {
+ return nil
+ }
+ if err != nil {
+ return err
+ }
+ if err := deleteIndex(ctx, id); err != nil {
+ return err
}
- _, err := deleteScript.Do(c, path)
+ _, err = deleteScript.Do(c, path)
return err
}
diff --git a/gddo-server/assets/templates/common.html b/gddo-server/assets/templates/common.html
index bcbf071..d472e00 100644
--- a/gddo-server/assets/templates/common.html
+++ b/gddo-server/assets/templates/common.html
@@ -51,11 +51,11 @@
{{if .Path|isValidImportPath}}
{{.Path|importPath}}
- {{if gaeSearch}}
+
- {{.ImportCount}} imports
{{if .Fork}}- · fork
{{end}}
{{if .Stars}}- · {{.Stars}} stars
{{end}}
- {{end}}
+
{{else}}{{.Path|importPath}} |
{{end}}
{{.Synopsis|importPath}} |
diff --git a/gddo-server/main.go b/gddo-server/main.go
index e0f62e6..bffe2da 100644
--- a/gddo-server/main.go
+++ b/gddo-server/main.go
@@ -583,16 +583,8 @@ func serveHome(resp http.ResponseWriter, req *http.Request) error {
}
}
- var (
- pkgs []database.Package
- err error
- )
- if database.GAESearch {
- ctx := appengine.NewContext(req)
- pkgs, err = database.Search(ctx, q)
- } else {
- pkgs, err = db.Query(q)
- }
+ ctx := appengine.NewContext(req)
+ pkgs, err := database.Search(ctx, q)
if err != nil {
return err
}
@@ -651,7 +643,8 @@ func serveAPISearch(resp http.ResponseWriter, req *http.Request) error {
if pkgs == nil {
var err error
- pkgs, err = db.Query(q)
+ ctx := appengine.NewContext(req)
+ pkgs, err = database.Search(ctx, q)
if err != nil {
return err
}
@@ -883,7 +876,6 @@ func init() {
flag.StringVar(&database.RedisServer, "db-server", database.RedisServer, "URI of Redis server.")
flag.DurationVar(&database.RedisIdleTimeout, "db-idle-timeout", database.RedisIdleTimeout, "Close Redis connections after remaining idle for this duration.")
flag.BoolVar(&database.RedisLog, "db-log", database.RedisLog, "Log database commands")
- flag.BoolVar(&database.GAESearch, "gae_search", database.GAESearch, "Use GAE Search API in the search function.")
}
func main() {
@@ -1038,10 +1030,6 @@ func main() {
gceLogger = newGCELogger(logc)
}
- if database.GAESearch {
- http.Handle("/", root)
- appengine.Main()
- } else {
- log.Fatal(http.ListenAndServe(*httpAddr, root))
- }
+ http.Handle("/", root)
+ appengine.Main()
}
diff --git a/gddo-server/template.go b/gddo-server/template.go
index d9032ac..99a4733 100644
--- a/gddo-server/template.go
+++ b/gddo-server/template.go
@@ -25,7 +25,6 @@ import (
ttemp "text/template"
"time"
- "github.com/golang/gddo/database"
"github.com/golang/gddo/doc"
"github.com/golang/gddo/gosrc"
"github.com/golang/gddo/httputil"
@@ -477,10 +476,6 @@ func gaAccountFn() string {
return gaAccount
}
-func gaeSearchFn() bool {
- return database.GAESearch
-}
-
func noteTitleFn(s string) string {
return strings.Title(strings.ToLower(s))
}
@@ -535,7 +530,6 @@ func parseHTMLTemplates(sets [][]string) error {
"comment": commentFn,
"equal": reflect.DeepEqual,
"gaAccount": gaAccountFn,
- "gaeSearch": gaeSearchFn,
"host": hostFn,
"htmlComment": htmlCommentFn,
"importPath": importPathFn,