perf and update fixes

This commit is contained in:
Thomas Rudin 2019-02-07 19:48:05 +01:00
parent a5a281cc21
commit 438ca52211
5 changed files with 41 additions and 50 deletions

View File

@ -37,7 +37,7 @@ var RealtimeTileLayer = L.TileLayer.extend({
createTile: function(coords){ createTile: function(coords){
var tile = document.createElement('img'); var tile = document.createElement('img');
tile.src = this.getTileSource(coords.x, coords.y, coords.z); tile.src = this.getTileSource(coords.x, coords.y, coords.z, true);
tile.id = this.getImageId(coords.x, coords.y, coords.z); tile.id = this.getImageId(coords.x, coords.y, coords.z);
return tile; return tile;
} }

View File

@ -44,23 +44,9 @@ const (
IMG_SIZE = 256 IMG_SIZE = 256
) )
func (tr *TileRenderer) Render(tc *coords.TileCoords, recursionDepth int) ([]byte, error) { func (tr *TileRenderer) Render(tc *coords.TileCoords) ([]byte, error) {
//Check cache
tile, err := tr.tdb.GetTile(tc)
if err != nil {
return nil, err
}
if tile == nil {
if recursionDepth == 0 {
log.WithFields(logrus.Fields{"x": tc.X, "y": tc.Y, "zoom": tc.Zoom}).Debug("Skip image")
return nil, nil
}
//No tile in db //No tile in db
img, data, err := tr.RenderImage(tc, recursionDepth) img, data, err := tr.RenderImage(tc, 2)
if err != nil { if err != nil {
return nil, err return nil, err
@ -72,13 +58,11 @@ func (tr *TileRenderer) Render(tc *coords.TileCoords, recursionDepth int) ([]byt
} }
return data, nil return data, nil
}
return tile.Data, nil
} }
func (tr *TileRenderer) RenderImage(tc *coords.TileCoords, recursionDepth int) (*image.NRGBA, []byte, error) { func (tr *TileRenderer) RenderImage(tc *coords.TileCoords, recursionDepth int) (*image.NRGBA, []byte, error) {
if recursionDepth < 2 {
cachedtile, err := tr.tdb.GetTile(tc) cachedtile, err := tr.tdb.GetTile(tc)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -102,6 +86,7 @@ func (tr *TileRenderer) RenderImage(tc *coords.TileCoords, recursionDepth int) (
log.WithFields(logrus.Fields{"x": tc.X, "y": tc.Y, "zoom": tc.Zoom}).Debug("Cached image") log.WithFields(logrus.Fields{"x": tc.X, "y": tc.Y, "zoom": tc.Zoom}).Debug("Cached image")
return img, cachedtile.Data, nil return img, cachedtile.Data, nil
} }
}
if recursionDepth == 0 { if recursionDepth == 0 {
log.WithFields(logrus.Fields{"x": tc.X, "y": tc.Y, "zoom": tc.Zoom}).Debug("Skip image") log.WithFields(logrus.Fields{"x": tc.X, "y": tc.Y, "zoom": tc.Zoom}).Debug("Skip image")

View File

@ -7,11 +7,8 @@ import (
func worker(ctx *app.App, coords <-chan *coords.TileCoords) { func worker(ctx *app.App, coords <-chan *coords.TileCoords) {
for tc := range coords { for tc := range coords {
//remove tile
ctx.Objectdb.RemoveTile(tc)
//render tile //render tile
_, err := ctx.Tilerenderer.Render(tc, 5) _, err := ctx.Tilerenderer.Render(tc)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -1,11 +1,12 @@
package web package web
import ( import (
"github.com/sirupsen/logrus"
"mapserver/app" "mapserver/app"
"mapserver/vfs" "mapserver/vfs"
"net/http" "net/http"
"strconv" "strconv"
"github.com/sirupsen/logrus"
) )
func Serve(ctx *app.App) { func Serve(ctx *app.App) {
@ -18,7 +19,10 @@ func Serve(ctx *app.App) {
mux := http.NewServeMux() mux := http.NewServeMux()
mux.Handle("/", http.FileServer(vfs.FS(ctx.Config.Webdev))) mux.Handle("/", http.FileServer(vfs.FS(ctx.Config.Webdev)))
mux.Handle("/api/tile/", &Tiles{ctx: ctx})
tiles := &Tiles{ctx: ctx}
tiles.Init()
mux.Handle("/api/tile/", tiles)
mux.Handle("/api/config", &ConfigHandler{ctx: ctx}) mux.Handle("/api/config", &ConfigHandler{ctx: ctx})
mux.Handle("/api/minetest", &Minetest{ctx: ctx}) mux.Handle("/api/minetest", &Minetest{ctx: ctx})
mux.Handle("/api/mapobjects/", &MapObjects{ctx: ctx}) mux.Handle("/api/mapobjects/", &MapObjects{ctx: ctx})

View File

@ -12,6 +12,11 @@ import (
type Tiles struct { type Tiles struct {
ctx *app.App ctx *app.App
blank []byte
}
func (t *Tiles) Init() {
t.blank = tilerenderer.CreateBlankTile(color.RGBA{255, 255, 255, 255})
} }
func (t *Tiles) ServeHTTP(resp http.ResponseWriter, req *http.Request) { func (t *Tiles) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
@ -40,7 +45,7 @@ func (t *Tiles) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
resp.Header().Add("content-type", "image/png") resp.Header().Add("content-type", "image/png")
if tile == nil { if tile == nil {
resp.Write(tilerenderer.CreateBlankTile(color.RGBA{255, 255, 255, 255})) resp.Write(t.blank)
//TODO: cache/layer color //TODO: cache/layer color
} else { } else {