Skip to content

Commit

Permalink
remove assignTemplates
Browse files Browse the repository at this point in the history
  • Loading branch information
dbauszus-glx committed Oct 20, 2023
1 parent cd4224d commit e9f1bad
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 67 deletions.
61 changes: 0 additions & 61 deletions mod/workspace/assignTemplates.js

This file was deleted.

65 changes: 59 additions & 6 deletions mod/workspace/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const getFrom = {
'mongodb': ref => mongodb(ref.split(/:(.*)/s)[1])
}

const assignTemplates = require('./assignTemplates')

const assignDefaults = require('./assignDefaults')

process.env.WORKSPACE_AGE ??= 3600000
Expand All @@ -30,17 +28,17 @@ module.exports = async () => {
// Cache workspace if empty.
if (!workspace) {
await cache()
logger(`Workspace empty; Time to cache: ${Date.now()-timestamp}`, 'workspace')
logger(`Workspace empty; Time to cache: ${Date.now() - timestamp}`, 'workspace')
}

// Logically assign timestamp.
workspace.timestamp ??= timestamp

// Cache workspace if expired.
if ((timestamp - workspace.timestamp) > +process.env.WORKSPACE_AGE) {

await cache()
logger(`Workspace cache expired; Time to cache: ${Date.now()-timestamp}`, 'workspace')
logger(`Workspace cache expired; Time to cache: ${Date.now() - timestamp}`, 'workspace')
workspace.timestamp = timestamp
}

Expand All @@ -56,7 +54,62 @@ async function cache() {
// Return error if source failed.
if (workspace instanceof Error) return workspace

await assignTemplates(workspace)
// Assign default view and query templates to workspace.
workspace.templates = {
// Query templates:
gaz_query: {
template: require('./templates/gaz_query'),
},
get_last_location: {
template: require('./templates/get_last_location'),
},
distinct_values: {
template: require('./templates/distinct_values'),
},
field_stats: {
template: require('./templates/field_stats'),
},
field_min: {
template: require('./templates/field_min'),
},
field_max: {
template: require('./templates/field_max'),
},
get_nnearest: {
render: require('./templates/get_nnearest'),
},
geojson: {
render: require('./templates/geojson'),
},
cluster: {
render: require('./templates/cluster'),
reduce: true
},
cluster_hex: {
render: require('./templates/cluster_hex'),
reduce: true
},
wkt: {
render: require('./templates/wkt'),
reduce: true
},
infotip: {
render: require('./templates/infotip'),
},
layer_extent: {
template: require('./templates/layer_extent'),
},
mvt_cache: {
admin: true,
render: require('./templates/mvt_cache'),
},
mvt_cache_delete_intersects: {
template: require('./templates/mvt_cache_delete_intersects'),
},

// Default templates can be overridden by assigning a template with the same name.
...workspace.templates
}

await assignDefaults(workspace)

Expand Down

0 comments on commit e9f1bad

Please sign in to comment.