Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: break out early if no tile found #97

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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