Skip to content

Commit

Permalink
Merge pull request #5945 from beyondessential/dev
Browse files Browse the repository at this point in the history
merge: update branch with latest dev
  • Loading branch information
avaek authored Oct 6, 2024
2 parents 8bbf44b + 60ce162 commit 2dadd6e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/admin-panel/src/importExport/ExportButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const ExportButton = ({ actionConfig, row }) => {
await api.download(
endpoint,
{ queryParameters, ...extraQueryParameters },
processedFileName,
`${processedFileName}.json`,
);
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export async function updateCountryEntities(
countryCode,
pushToDhis,
);

await transactingModels.entity.findOrCreate(
{ code: countryCode },
{
Expand All @@ -103,6 +104,7 @@ export async function updateCountryEntities(
},
);
const codes = []; // An array to hold all facility codes, allowing duplicate checking

for (let i = 0; i < entityObjects.length; i++) {
const entityObject = entityObjects[i];
const { entity_type: entityType } = entityObject;
Expand Down Expand Up @@ -192,7 +194,27 @@ export async function updateCountryEntities(
geojson.type === 'Polygon'
? { type: 'MultiPolygon', coordinates: [geojson.coordinates] }
: geojson;
await transactingModels.entity.updateRegionCoordinates(code, translatedGeojson);

try {
await transactingModels.entity.updateRegionCoordinates(code, translatedGeojson);
} catch (error) {
if (error.message.includes('payload string too long')) {
const largeGeoEntities = entityObjects.filter(entityObject => {
if (!entityObject?.geojson) return false;
const geoJsonString = JSON.stringify(entityObject.geojson);
// If the geo json is too large, we will hit the max payload size limit.
// Hard postgres max is 8000 characters, but we need to account for other data in the query payload
const maxGeoJsonPayload = 5200;
if (geoJsonString.length > maxGeoJsonPayload) {
return true;
}
});
const text = largeGeoEntities.map(entity => entity.code).join(', ');
error.message = `Error updating region coordinates for entities: ${text} ${error.message}`;
}

throw error;
}
}
}
return country;
Expand Down
9 changes: 8 additions & 1 deletion packages/database/src/TupaiaDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,8 @@ function addWhereClause(connection, baseQuery, where) {
return querySoFar; // Ignore undefined criteria
}
if (value === null) {
return querySoFar.whereNull(key);
const columnKey = getColSelector(connection, key);
return querySoFar.whereNull(columnKey);
}
const {
comparisonType = 'where',
Expand Down Expand Up @@ -748,5 +749,11 @@ function getColSelector(connection, inputColStr) {
return connection.raw(inputColStr);
}

const asGeoJsonPattern = /^ST_AsGeoJSON\((.+)\)$/;
if (asGeoJsonPattern.test(inputColStr)) {
const [, argsString] = inputColStr.match(asGeoJsonPattern);
return connection.raw(`ST_AsGeoJSON(${argsString})`);
}

return inputColStr;
}

0 comments on commit 2dadd6e

Please sign in to comment.