From 51b7f8969a86c70bd65da894136331b85df86347 Mon Sep 17 00:00:00 2001 From: Jens Zeilund Date: Mon, 30 Oct 2023 23:28:10 +0100 Subject: [PATCH] refactor: break out early if no tile found (#97) --- pmtiles/server.go | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/pmtiles/server.go b/pmtiles/server.go index d102781..5e01867 100644 --- a/pmtiles/server.go +++ b/pmtiles/server.go @@ -324,30 +324,30 @@ func (server *Server) get_tile(ctx context.Context, http_headers map[string]stri dir_value := <-dir_req.value directory := dir_value.directory entry, ok := find_tile(directory, tile_id) - if ok { - if entry.RunLength > 0 { - r, err := server.bucket.NewRangeReader(ctx, name+".pmtiles", int64(header.TileDataOffset+entry.Offset), int64(entry.Length)) - if err != nil { - return 500, http_headers, []byte("Network error") - } - defer r.Close() - b, err := io.ReadAll(r) - if err != nil { - return 500, http_headers, []byte("I/O error") - } - if header_val, ok := headerContentType(header); ok { - http_headers["Content-Type"] = header_val - } - if header_val, ok := headerContentEncoding(header.TileCompression); ok { - http_headers["Content-Encoding"] = header_val - } - return 200, http_headers, b - } else { - dir_offset = header.LeafDirectoryOffset + entry.Offset - dir_len = uint64(entry.Length) + if !ok { + break + } + + if entry.RunLength > 0 { + r, err := server.bucket.NewRangeReader(ctx, name+".pmtiles", int64(header.TileDataOffset+entry.Offset), int64(entry.Length)) + if err != nil { + return 500, http_headers, []byte("Network error") + } + defer r.Close() + b, err := io.ReadAll(r) + if err != nil { + return 500, http_headers, []byte("I/O error") + } + if header_val, ok := headerContentType(header); ok { + http_headers["Content-Type"] = header_val } + if header_val, ok := headerContentEncoding(header.TileCompression); ok { + http_headers["Content-Encoding"] = header_val + } + return 200, http_headers, b } else { - break + dir_offset = header.LeafDirectoryOffset + entry.Offset + dir_len = uint64(entry.Length) } }