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

Add ttl to fetch promises, check metadata rows before fetching #80

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions src/mosaic.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ async function mosaic512px(z, x, y, filters = {}) {
const metadataByUuid = {};
await Promise.all(
rows.map(async (row) => {
metadataByUuid[row.uuid] = await getGeotiffMetadata(row.uuid);
if (row && row.uuid) {
metadataByUuid[row.uuid] = await getGeotiffMetadata(row.uuid);
}
dqunbp marked this conversation as resolved.
Show resolved Hide resolved
})
);

const tilePromises = [];
if (z < 9) {
for (const row of rows) {
Expand Down
4 changes: 2 additions & 2 deletions src/mosaic_viewer.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<script>
// get zoom and center from url hash
const hash = window.location.hash.slice(1).split("/");
const [zoom = 0, lng = 0, lat = 0] = hash.filter(Boolean).map(parseFloat);
const [zoom = 0, lat = 0, lng = 0] = hash.filter(Boolean).map(parseFloat);
mapboxgl.accessToken = "";
const map = new mapboxgl.Map({
container: "map",
Expand Down Expand Up @@ -96,7 +96,7 @@
map.on("moveend", () => {
const { lng, lat } = map.getCenter();
const zoom = map.getZoom();
window.location.hash = `#${zoom.toFixed(2)}/${lng.toFixed(4)}/${lat.toFixed(4)}`;
window.location.hash = `#${zoom.toFixed(2)}/${lat.toFixed(4)}/${lng.toFixed(4)}`;
dqunbp marked this conversation as resolved.
Show resolved Hide resolved
});
</script>
</body>
Expand Down
4 changes: 3 additions & 1 deletion src/titiler_fetcher.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ async function fetchTile(url) {
}
}

const FETCH_QUEUE_TTL = parseInt(process.env.TILE_FETCH_TTL_MS, 10) || 1000 * 60 * 10; // 10 minutes default
dqunbp marked this conversation as resolved.
Show resolved Hide resolved

async function enqueueTileFetching(tileUrl, z, x, y) {
const url = tileUrl.replace("{z}", z).replace("{x}", x).replace("{y}", y);
if (activeTileRequests.get(url)) {
return activeTileRequests.get(url);
}

const request = tileRequestQueue
.add(() => fetchTile(url), { priority: z })
.add(() => fetchTile(url), { priority: z, timeout: FETCH_QUEUE_TTL })
dqunbp marked this conversation as resolved.
Show resolved Hide resolved
.finally(() => {
activeTileRequests.delete(url);
});
Expand Down
Loading