Skip to content

Commit

Permalink
Geodatasets to use spatial index, also DB_POOL envs
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Mar 13, 2024
1 parent eddc4ae commit f5188db
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 19 deletions.
63 changes: 51 additions & 12 deletions API/Backend/Geodatasets/models/geodatasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,32 @@ function makeNewGeodatasetTable(name, success, failure) {
{ where: { name: name }, silent: true }
)
.then((r) => {
success({
name: result.dataValues.name,
table: result.dataValues.table,
tableObj: GeodatasetTable,
});
sequelize
.query(
`CREATE INDEX IF NOT EXISTS ${result.dataValues.table}_geom_idx on ${result.dataValues.table} USING gist (geom);`
)
.then(() => {
success({
name: result.dataValues.name,
table: result.dataValues.table,
tableObj: GeodatasetTable,
});

return null;
return null;
})
.catch((err) => {
logger(
"error",
"Failed to recreate spatial index for geodataset table.",
"geodatasets",
null,
err
);
failure({
status: "failure",
message: "Failed to recreate spatial index",
});
});
})
.catch((err) => {
logger(
Expand All @@ -89,6 +108,7 @@ function makeNewGeodatasetTable(name, success, failure) {
.then(([results]) => {
let newTable =
"g" + (parseInt(results[0].count) + 1) + "_geodatasets";

Geodatasets.create({
name: name,
table: newTable,
Expand All @@ -102,12 +122,31 @@ function makeNewGeodatasetTable(name, success, failure) {
sequelize
.sync()
.then(() => {
success({
name: name,
table: newTable,
tableObj: GeodatasetTable,
});
return null;
sequelize
.query(
`CREATE INDEX ${newTable}_geom_idx on ${newTable} USING gist (geom);`
)
.then(() => {
success({
name: name,
table: newTable,
tableObj: GeodatasetTable,
});
return null;
})
.catch((err) => {
logger(
"error",
"Failed to create spatial index for geodataset table.",
"geodatasets",
null,
err
);
failure({
status: "failure",
message: "Failed to create spatial index",
});
});
})
.catch((err) => {
logger(
Expand Down
23 changes: 19 additions & 4 deletions API/Backend/Geodatasets/routes/geodatasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,30 @@ function populateGeodatasetTable(Table, features, cb) {

Table.bulkCreate(rows, { returning: true })
.then(function (response) {
cb(true);
return null;
sequelize
.query(`VACUUM ANALYZE ${Table.tableName};`)
.then(() => {
cb(true);
return null;
})
.catch((err) => {
logger(
"error",
"Geodatasets: Failed to vacuum a geodataset spatial index!",
null,
null,
err
);
cb(false);
return null;
});
})
.catch(function (err) {
logger(
"error",
"Geodatasets: Failed to populate a geodataset table!",
req.originalUrl,
req,
null,
null,
err
);
cb(false);
Expand Down
15 changes: 12 additions & 3 deletions API/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@ const sequelize = new Sequelize(
dialect: "postgres",
logging: process.env.VERBOSE_LOGGING == "true" || false,
pool: {
max: 10,
max:
process.env.DB_POOL_MAX != null
? parseInt(process.env.DB_POOL_MAX) || 10
: 10,
min: 0,
acquire: 30000,
idle: 10000,
acquire:
process.env.DB_POOL_TIMEOUT != null
? parseInt(process.env.DB_POOL_TIMEOUT) || 30000
: 30000,
idle:
process.env.DB_POOL_IDLE != null
? parseInt(process.env.DB_POOL_IDLE) || 10000
: 10000,
},
}
);
Expand Down
12 changes: 12 additions & 0 deletions docs/pages/Setup/ENVs/ENVs.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ User of Postgres database | string | default `null`

Password of Postgres database | string | default `null`

#### `DB_POOL_MAX=`

Max number connections in the database's pool. CPUs \* 4 is a good number | integer | default `10`

#### `DB_POOL_TIMEOUT=`

How many milliseconds until a DB connection times out | integer | default `30000` (30 sec)

#### `DB_POOL_IDLE=`

How many milliseconds for an incoming connection to wait for a DB connection before getting kicked away | integer | default `10000` (10 sec)

#### `CSSO_GROUPS=`

A list of CSSO LDAP groups that have access | string[] | default `[]`
Expand Down
6 changes: 6 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ DB_PORT=5432
DB_NAME=name
DB_USER=user
DB_PASS=password
# Max number connections in the database's pool. CPUs * 4 is a good number. Default is 10
DB_POOL_MAX=
# How many milliseconds until a DB connection times out. Default is 30000 (30 sec)
DB_POOL_TIMEOUT=
# How many milliseconds for an incoming connection to wait for a DB connection before getting kicked away. Default is 10000 (10 sec)
DB_POOL_IDLE=

#CONFIG
# Disable the configure page
Expand Down

0 comments on commit f5188db

Please sign in to comment.