Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge: update branch with latest dev #5945

Merged
merged 2 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}