gddo-server: Remove the gae_search flag.

Use app engine's main function to start the server by default. GAE
search is also enabled by default. API search is also using the new
search algorithm.

Developers will need to install Google Cloud SDK to use dev_appserver
in order to run the search api locally. The development setup will be
updated as soon as this CL is submitted.

Change-Id: Idae7a88949b2757977d0ab33628564451a1dddd3
Reviewed-on: https://go-review.googlesource.com/25360
Reviewed-by: Andrew Gerrand <adg@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Tuo Shan 2016-07-29 09:12:55 -07:00 коммит произвёл Alan Donovan
Родитель b828973d90
Коммит e0d34163be
4 изменённых файлов: 34 добавлений и 57 удалений

Просмотреть файл

@ -85,7 +85,6 @@ var (
RedisServer = "redis://127.0.0.1:6379" // URL of Redis server RedisServer = "redis://127.0.0.1:6379" // URL of Redis server
RedisIdleTimeout = 250 * time.Second // Close Redis connections after remaining idle for this duration. RedisIdleTimeout = 250 * time.Second // Close Redis connections after remaining idle for this duration.
RedisLog = false // Log database commands RedisLog = false // Log database commands
GAESearch = false // Use GAE Search API in the search function.
) )
func dialDb() (c redis.Conn, err error) { 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 return err
} }
if GAESearch { id, n, err := pkgIDAndImportCount(c, pdoc.ImportPath)
id, n, err := pkgIDAndImportCount(c, pdoc.ImportPath) if err != nil {
if err != nil { return err
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 old != nil {
if err := PutIndex(ctx, pdoc, id, score, n); err != nil { if err := updateImportsIndex(c, ctx, old, pdoc); 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 {
return err return err
} }
} }
} else {
if err := deleteIndex(ctx, id); err != nil {
return err
}
} }
if nextCrawl.IsZero() { if nextCrawl.IsZero() {
@ -607,21 +604,19 @@ func (db *Database) Delete(path string) error {
c := db.Pool.Get() c := db.Pool.Get()
defer c.Close() defer c.Close()
if GAESearch { ctx := bgCtx()
ctx := bgCtx() id, err := redis.String(c.Do("HGET", "ids", path))
id, err := redis.String(c.Do("HGET", "ids", path)) if err == redis.ErrNil {
if err == redis.ErrNil { return nil
return nil }
} if err != nil {
if err != nil { return err
return err }
} if err := deleteIndex(ctx, id); err != nil {
if err := deleteIndex(ctx, id); err != nil { return err
return err
}
} }
_, err := deleteScript.Do(c, path) _, err = deleteScript.Do(c, path)
return err return err
} }

Просмотреть файл

@ -51,11 +51,11 @@
<tr><td> <tr><td>
{{if .Path|isValidImportPath}} {{if .Path|isValidImportPath}}
<a href="/{{.Path}}">{{.Path|importPath}}</a> <a href="/{{.Path}}">{{.Path|importPath}}</a>
{{if gaeSearch}}<ul class="list-inline"> <ul class="list-inline">
<li class="additional-info">{{.ImportCount}} imports</li> <li class="additional-info">{{.ImportCount}} imports</li>
{{if .Fork}}<li class="additional-info">· fork</li>{{end}} {{if .Fork}}<li class="additional-info">· fork</li>{{end}}
{{if .Stars}}<li class="additional-info">· {{.Stars}} stars</li>{{end}} {{if .Stars}}<li class="additional-info">· {{.Stars}} stars</li>{{end}}
</ul>{{end}} </ul>
{{else}}{{.Path|importPath}}</td> {{else}}{{.Path|importPath}}</td>
{{end}} {{end}}
<td class="synopsis">{{.Synopsis|importPath}}</td></tr> <td class="synopsis">{{.Synopsis|importPath}}</td></tr>

Просмотреть файл

@ -583,16 +583,8 @@ func serveHome(resp http.ResponseWriter, req *http.Request) error {
} }
} }
var ( ctx := appengine.NewContext(req)
pkgs []database.Package pkgs, err := database.Search(ctx, q)
err error
)
if database.GAESearch {
ctx := appengine.NewContext(req)
pkgs, err = database.Search(ctx, q)
} else {
pkgs, err = db.Query(q)
}
if err != nil { if err != nil {
return err return err
} }
@ -651,7 +643,8 @@ func serveAPISearch(resp http.ResponseWriter, req *http.Request) error {
if pkgs == nil { if pkgs == nil {
var err error var err error
pkgs, err = db.Query(q) ctx := appengine.NewContext(req)
pkgs, err = database.Search(ctx, q)
if err != nil { if err != nil {
return err return err
} }
@ -883,7 +876,6 @@ func init() {
flag.StringVar(&database.RedisServer, "db-server", database.RedisServer, "URI of Redis server.") 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.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.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() { func main() {
@ -1038,10 +1030,6 @@ func main() {
gceLogger = newGCELogger(logc) gceLogger = newGCELogger(logc)
} }
if database.GAESearch { http.Handle("/", root)
http.Handle("/", root) appengine.Main()
appengine.Main()
} else {
log.Fatal(http.ListenAndServe(*httpAddr, root))
}
} }

Просмотреть файл

@ -25,7 +25,6 @@ import (
ttemp "text/template" ttemp "text/template"
"time" "time"
"github.com/golang/gddo/database"
"github.com/golang/gddo/doc" "github.com/golang/gddo/doc"
"github.com/golang/gddo/gosrc" "github.com/golang/gddo/gosrc"
"github.com/golang/gddo/httputil" "github.com/golang/gddo/httputil"
@ -477,10 +476,6 @@ func gaAccountFn() string {
return gaAccount return gaAccount
} }
func gaeSearchFn() bool {
return database.GAESearch
}
func noteTitleFn(s string) string { func noteTitleFn(s string) string {
return strings.Title(strings.ToLower(s)) return strings.Title(strings.ToLower(s))
} }
@ -535,7 +530,6 @@ func parseHTMLTemplates(sets [][]string) error {
"comment": commentFn, "comment": commentFn,
"equal": reflect.DeepEqual, "equal": reflect.DeepEqual,
"gaAccount": gaAccountFn, "gaAccount": gaAccountFn,
"gaeSearch": gaeSearchFn,
"host": hostFn, "host": hostFn,
"htmlComment": htmlCommentFn, "htmlComment": htmlCommentFn,
"importPath": importPathFn, "importPath": importPathFn,