Skip to content

Commit

Permalink
Fix tile compression
Browse files Browse the repository at this point in the history
  • Loading branch information
bchapuis committed Oct 24, 2023
1 parent b7e9741 commit 13d3776
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 264 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ public class PostgresTileStore implements TileStore {

private static final Logger logger = LoggerFactory.getLogger(PostgresTileStore.class);

public static final String CONTENT_ENCODING = "gzip";

public static final String CONTENT_TYPE = "application/vnd.mapbox-vector-tile";

private final DataSource datasource;

private final Tileset tileset;
Expand Down Expand Up @@ -100,7 +96,6 @@ WHERE t.geom && ST_TileEnvelope(%d, %d, %d, margin => (64.0/4096))
tileCoord.z(), tileCoord.x(), tileCoord.y(),
layerQuery,
tileCoord.z(), tileCoord.x(), tileCoord.y()));

}

queryBuilder.append(sqlBuilder)
Expand All @@ -121,31 +116,31 @@ public ByteBuffer read(TileCoord tileCoord) throws TileStoreException {

try (Connection connection = datasource.getConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query)) {
ResultSet resultSet = statement.executeQuery(query);
ByteArrayOutputStream data = new ByteArrayOutputStream()) {

int length = 0;
try (ByteArrayOutputStream data = new ByteArrayOutputStream();
OutputStream gzip = new GZIPOutputStream(data)) {

try (OutputStream gzip = new GZIPOutputStream(data)) {
while (resultSet.next()) {
byte[] bytes = resultSet.getBytes(1);
length += bytes.length;
gzip.write(bytes);
}
}

long stop = System.currentTimeMillis();
long duration = stop - start;
long stop = System.currentTimeMillis();
long duration = stop - start;

// Log slow queries (> 10s)
if (duration > 10_000) {
logger.warn("Executed query for tile {} in {} ms: {}", tileCoord, duration, query);
}
// Log slow queries (> 10s)
if (duration > 10_000) {
logger.warn("Executed query for tile {} in {} ms: {}", tileCoord, duration, query);
}

if (length > 0) {
return ByteBuffer.wrap(data.toByteArray());
} else {
return ByteBuffer.allocate(0);
}
if (length > 0) {
return ByteBuffer.wrap(data.toByteArray());
} else {
return ByteBuffer.allocate(0);
}
} catch (Exception e) {
logger.error(e.getMessage());
Expand Down
4 changes: 0 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ limitations under the License.
<version.lib.jakarta>2.1.6</version.lib.jakarta>
<version.lib.jersey>2.37</version.lib.jersey>
<version.lib.jmh>1.35</version.lib.jmh>
<<<<<<< HEAD
<version.lib.jsqlparser>4.7</version.lib.jsqlparser>
=======
>>>>>>> 74c2f1de (Improve tilestore queries and remove jsqlparser)
<version.lib.jts>1.19.0</version.lib.jts>
<version.lib.junit>5.10.0</version.lib.junit>
<version.lib.junit-vintage>5.10.0</version.lib.junit-vintage>
Expand Down

0 comments on commit 13d3776

Please sign in to comment.