From 13cab545b1fda53a8086a8a0ff55aaf31d1d04e4 Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Mon, 21 Jan 2019 13:41:47 +0100 Subject: [PATCH] update job --- db/sqlite.go | 2 +- initialrenderer/job.go | 2 +- tileupdate/job.go | 53 +++++++++++++++++++++++++++++++++++++----- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/db/sqlite.go b/db/sqlite.go index f9c4895..3bd6b78 100644 --- a/db/sqlite.go +++ b/db/sqlite.go @@ -109,7 +109,7 @@ func (db *Sqlite3Accessor) FindLegacyBlocks(lastpos coords.MapBlockCoords, limit const getLatestBlockQuery = ` select pos,data,mtime from blocks b -where b.mtime >= ? +where b.mtime > ? order by b.mtime asc limit ? ` diff --git a/initialrenderer/job.go b/initialrenderer/job.go index d1ab219..a1453b9 100644 --- a/initialrenderer/job.go +++ b/initialrenderer/job.go @@ -17,7 +17,7 @@ func Job(ctx *app.App) { lastcoords := coords.NewMapBlockCoords(rstate.LastX, rstate.LastY, rstate.LastZ) for true { - newlastcoords, mblist, err := ctx.BlockAccessor.FindLegacyMapBlocks(lastcoords, 1000) + newlastcoords, mblist, err := ctx.BlockAccessor.FindLegacyMapBlocks(lastcoords, 10000) if err != nil { panic(err) diff --git a/tileupdate/job.go b/tileupdate/job.go index 3a9d6e6..fa9bff1 100644 --- a/tileupdate/job.go +++ b/tileupdate/job.go @@ -3,6 +3,8 @@ package tileupdate import ( "github.com/sirupsen/logrus" "mapserver/app" + "mapserver/coords" + "mapserver/mapblockparser" "time" ) @@ -15,25 +17,64 @@ func Job(ctx *app.App) { logrus.WithFields(fields).Info("Starting incremental update") for true { - mblist, err := ctx.BlockAccessor.FindLatestMapBlocks(rstate.LastMtime, 1000) + mblist, err := ctx.BlockAccessor.FindLatestMapBlocks(rstate.LastMtime, 10000) if err != nil { panic(err) } + //only mapblocks with valid layer + validmblist := make([]*mapblockparser.MapBlock, 0) + for _, mb := range mblist { if mb.Mtime > rstate.LastMtime { - rstate.LastMtime = mb.Mtime + 1 + rstate.LastMtime = mb.Mtime + } + + tc := coords.GetTileCoordsFromMapBlock(mb.Pos, ctx.Config.Layers) + + if tc == nil { + continue + } + + validmblist = append(validmblist, mb) + + for tc.Zoom > 1 { + tc = tc.GetZoomedOutTile() + ctx.Tiledb.RemoveTile(tc) + } + } + + //Render zoom 12-1 + for _, mb := range validmblist { + tc := coords.GetTileCoordsFromMapBlock(mb.Pos, ctx.Config.Layers) + for tc.Zoom > 1 { + tc = tc.GetZoomedOutTile() + + fields = logrus.Fields{ + "X": tc.X, + "Y": tc.Y, + "Zoom": tc.Zoom, + "LayerId": tc.LayerId, + } + logrus.WithFields(fields).Debug("Dispatching tile rendering (update)") + + _, err = ctx.Tilerenderer.Render(tc) + if err != nil { + panic(err) + } } } ctx.Config.Save() - fields = logrus.Fields{ - "count": len(mblist), - "lastmtime": rstate.LastMtime, + if len(mblist) > 0 { + fields = logrus.Fields{ + "count": len(mblist), + "lastmtime": rstate.LastMtime, + } + logrus.WithFields(fields).Info("incremental update") } - logrus.WithFields(fields).Info("incremental update") time.Sleep(5 * time.Second) }