Skip to content

Commit

Permalink
Merge pull request #292 from pelias/drop-bundle-support
Browse files Browse the repository at this point in the history
Always use sqlite as data source
  • Loading branch information
orangejulius authored Apr 23, 2020
2 parents 01cac83 + adedf14 commit bd31b26
Show file tree
Hide file tree
Showing 6 changed files with 796 additions and 1,009 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"pelias-config": "^4.0.0",
"pelias-logger": "^1.2.1",
"pelias-microservice-wrapper": "^1.2.1",
"pelias-whosonfirst": "^3.0.0",
"pelias-whosonfirst": "^4.0.0",
"polygon-lookup": "^2.1.0",
"request": "^2.83.0",
"simplify-js": "^1.2.1",
Expand Down
1 change: 0 additions & 1 deletion schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports = Joi.object().keys({
Joi.number().integer(),
Joi.array().items(Joi.number().integer())
],
sqlite: Joi.boolean().default(false).truthy('yes').falsy('no')
}).unknown(true),
services: Joi.object().keys({
pip: Joi.object().keys({
Expand Down
34 changes: 3 additions & 31 deletions src/pip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const async = require('async');
const _ = require('lodash');
const fs = require('fs');
const missingMetafilesAreFatal = require('pelias-config').generate(require('../../schema')).imports.adminLookup.missingMetafilesAreFatal;
const isSqlite = require('pelias-config').generate(require('../../schema')).imports.whosonfirst.sqlite;

let requestCount = 0;
// worker processes keyed on layer
Expand Down Expand Up @@ -43,36 +42,9 @@ module.exports.create = function createPIPService(datapath, layers, localizedAdm
// ie - _.intersection([1, 2, 3], [3, 1]) === [1, 3]
layers = _.intersection(defaultLayers, _.isEmpty(layers) ? defaultLayers : layers);

if (isSqlite === true) {
const folder = path.join(datapath, 'sqlite');
if (!fs.existsSync(folder)) {
return callback(`unable to locate sqlite folder`);
}
} else {
// keep track of any missing metafiles for later reporting and error conditions
const missingMetafiles = [];

// further refine the layers by filtering out layers for which there is no metafile
layers = layers.filter(layer => {
const filename = path.join(datapath, 'meta', `whosonfirst-data-${layer}-latest.csv`);

if (!fs.existsSync(filename)) {
const message = `unable to locate ${filename}`;
if (missingMetafilesAreFatal) {
logger.error(message);
} else {
logger.warn(message);
}
missingMetafiles.push(`whosonfirst-data-${layer}-latest.csv`);
return false;
}
return true;
});

// if there are missing metafiles and this is fatal, then return an error
if (!_.isEmpty(missingMetafiles) && missingMetafilesAreFatal) {
return callback(`unable to locate meta files in ${path.join(datapath, 'meta')}: ${missingMetafiles.join(', ')}`);
}
const folder = path.join(datapath, 'sqlite');
if (!fs.existsSync(folder)) {
return callback(`unable to locate sqlite folder`);
}

logger.info(`starting with layers ${layers}`);
Expand Down
16 changes: 2 additions & 14 deletions src/pip/readStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ const SQLiteStream = whosonfirst.SQLiteStream;

const SQLITE_REGEX = /whosonfirst-data-[a-z0-9-]+\.db$/;

function readBundleRecords(datapath, layer) {
return whosonfirst.metadataStream(datapath).create(layer)
.pipe(whosonfirst.parseMetaFiles())
.pipe(whosonfirst.isNotNullIslandRelated())
.pipe(whosonfirst.recordHasName())
.pipe(whosonfirst.loadJSON(datapath, false));
}

function getSqliteFilePaths(root) {
return fs.readdirSync(root)
.filter(d => SQLITE_REGEX.test(d))
Expand Down Expand Up @@ -54,11 +46,7 @@ function readSqliteRecords(datapath, layer) {
function readData(datapath, layer, localizedAdminNames, callback) {
const features = [];

const stream = config.sqlite === true ?
readSqliteRecords(datapath, layer) :
readBundleRecords(datapath, layer);

stream
readSqliteRecords(datapath,layer)
.pipe(whosonfirst.recordHasIdAndProperties())
.pipe(whosonfirst.isActiveRecord())
.pipe(filterOutPointRecords.create())
Expand All @@ -75,4 +63,4 @@ function readData(datapath, layer, localizedAdminNames, callback) {

}

module.exports = readData;
module.exports = readData;
Loading

0 comments on commit bd31b26

Please sign in to comment.