Commit 0a9d9246 authored by Anne Blankert's avatar Anne Blankert

better cache filenames, layer_columns uses schema

parent 120af7fb
......@@ -13,6 +13,7 @@ const sql = (params) => {
relnamespace = pg_namespace.oid AND
attnum >= 1 AND
relname = '${params.table}'
${params.schema?` AND nspname= '${params.schema}'`:''}
`
}
......@@ -40,6 +41,19 @@ module.exports = function (app, pool) {
* description: table not found or not accessible
*/
app.get('/data/layer_columns/:table', async (req, res)=> {
let tableName, schemaName;
const table = req.params.table;
if (table) {
const parts = table.split('.');
if (parts.length === 1) {
tableName = parts[0];
schemaName = null;
} else {
schemaName = parts[0];
tableName = parts[1];
}
req.params.table = tableName;
req.params.schema = schemaName;
const sqlString = sql(req.params, req.query);
try {
const result = await pool.query(sqlString);
......@@ -60,5 +74,9 @@ module.exports = function (app, pool) {
}
res.status(status).json({error:err.message})
}
})
} else {
res.status(422).json({error:"missing parameter 'table'"})
}
});
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
const sqlTableName = require('./utils/sqltablename.js');
const DirCache = require('./utils/dircache.js')
const cache = new DirCache('./cache/mvt');
const cache = new DirCache('./cache');
const sm = require('@mapbox/sphericalmercator');
const merc = new sm({
......@@ -10,8 +10,9 @@ const merc = new sm({
})
let cacheMiddleWare = async(req, res, next) => {
const cacheDir = `${req.params.datasource}/${req.params.z}/${req.params.x}/${req.params.y}`;
const key = (req.query.geom_column?req.query.geom_column:'geom') + req.query.columns?','+req.query.columns:'';
const cacheDir = `${req.params.datasource}/mvt/${req.params.z}/${req.params.x}/${req.params.y}`;
const key = ((req.query.geom_column?req.query.geom_column:'geom') + (req.query.columns?','+req.query.columns:''))
.replace(/[\W]+/g, '_');
const mvt = await cache.getCachedFile(cacheDir, key);
if (mvt) {
......
......@@ -24,7 +24,7 @@
document.querySelector('#tablename').innerHTML = fullTableName;
const parts = fullTableName.split('.');
const tableName = (parts.length > 1) ? parts[1] : parts[0];
fetch(`data/layer_columns/${tableName}`).then(response=>{
fetch(`data/layer_columns/${fullTableName}`).then(response=>{
const list = document.querySelector('#columns');
if (response.ok) {
response.json().then(json=> {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment