Skip to content

Commit

Permalink
refactor: break out early if no tile found (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
jzs authored Oct 30, 2023
1 parent 371f286 commit 51b7f89
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions pmtiles/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 51b7f89

Please sign in to comment.