forked from hans/Nominatim
be a bit efficient about queuing up the places to be indexed
This commit is contained in:
@@ -34,10 +34,12 @@ void nominatim_index(int rank_min, int rank_max, int num_threads, const char *co
|
|||||||
PGresult * res;
|
PGresult * res;
|
||||||
PGresult * resSectors;
|
PGresult * resSectors;
|
||||||
PGresult * resPlaces;
|
PGresult * resPlaces;
|
||||||
|
PGresult * resNULL;
|
||||||
|
|
||||||
int rank;
|
int rank;
|
||||||
int i;
|
int i;
|
||||||
int iSector;
|
int iSector;
|
||||||
|
int iResult;
|
||||||
|
|
||||||
const char *paramValues[2];
|
const char *paramValues[2];
|
||||||
int paramLengths[2];
|
int paramLengths[2];
|
||||||
@@ -183,7 +185,32 @@ void nominatim_index(int rank_min, int rank_max, int num_threads, const char *co
|
|||||||
}
|
}
|
||||||
|
|
||||||
rankStartTime = time(0);
|
rankStartTime = time(0);
|
||||||
for (iSector = 0; iSector < PQntuples(resSectors); iSector++)
|
for (iSector = 0; iSector <= PQntuples(resSectors); iSector++)
|
||||||
|
{
|
||||||
|
if (iSector > 0)
|
||||||
|
{
|
||||||
|
resPlaces = PQgetResult(conn);
|
||||||
|
if (PQresultStatus(resPlaces) != PGRES_TUPLES_OK)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "index_sector_places: SELECT failed: %s", PQerrorMessage(conn));
|
||||||
|
PQclear(resPlaces);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (PQftype(resPlaces, 0) != PG_OID_INT4)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Place_id value has unexpected type\n");
|
||||||
|
PQclear(resPlaces);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
resNULL = PQgetResult(conn);
|
||||||
|
if (resNULL != NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Unexpected non-null response\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iSector < PQntuples(resSectors))
|
||||||
{
|
{
|
||||||
sector = PGint32(*((uint32_t *)PQgetvalue(resSectors, iSector, 0)));
|
sector = PGint32(*((uint32_t *)PQgetvalue(resSectors, iSector, 0)));
|
||||||
//printf("\n Starting sector %d size %ld\n", sector, PGint64(*((uint64_t *)PQgetvalue(resSectors, iSector, 1))));
|
//printf("\n Starting sector %d size %ld\n", sector, PGint64(*((uint64_t *)PQgetvalue(resSectors, iSector, 1))));
|
||||||
@@ -198,22 +225,19 @@ void nominatim_index(int rank_min, int rank_max, int num_threads, const char *co
|
|||||||
paramLengths[1] = sizeof(paramSector);
|
paramLengths[1] = sizeof(paramSector);
|
||||||
paramFormats[1] = 1;
|
paramFormats[1] = 1;
|
||||||
if (rank < 16)
|
if (rank < 16)
|
||||||
resPlaces = PQexecPrepared(conn, "index_nosector_places", 1, paramValues, paramLengths, paramFormats, 1);
|
iResult = PQsendQueryPrepared(conn, "index_nosector_places", 1, paramValues, paramLengths, paramFormats, 1);
|
||||||
else
|
else
|
||||||
resPlaces = PQexecPrepared(conn, "index_sector_places", 2, paramValues, paramLengths, paramFormats, 1);
|
iResult = PQsendQueryPrepared(conn, "index_sector_places", 2, paramValues, paramLengths, paramFormats, 1);
|
||||||
if (PQresultStatus(resPlaces) != PGRES_TUPLES_OK)
|
if (!iResult)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "index_sector_places: SELECT failed: %s", PQerrorMessage(conn));
|
fprintf(stderr, "index_sector_places: SELECT failed: %s", PQerrorMessage(conn));
|
||||||
PQclear(resPlaces);
|
PQclear(resPlaces);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if (PQftype(resPlaces, 0) != PG_OID_INT4)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Place_id value has unexpected type\n");
|
|
||||||
PQclear(resPlaces);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (iSector > 0)
|
||||||
|
{
|
||||||
count = 0;
|
count = 0;
|
||||||
rankPerSecond = 0;
|
rankPerSecond = 0;
|
||||||
tuples = PQntuples(resPlaces);
|
tuples = PQntuples(resPlaces);
|
||||||
@@ -261,7 +285,7 @@ void nominatim_index(int rank_min, int rank_max, int num_threads, const char *co
|
|||||||
printf(" Done %i in %i @ %f per second - ETA (seconds): %f\n", rankCountTuples, (int)(difftime(time(0), rankStartTime)), rankPerSecond, ((float)(rankTotalTuples - rankCountTuples))/rankPerSecond);
|
printf(" Done %i in %i @ %f per second - ETA (seconds): %f\n", rankCountTuples, (int)(difftime(time(0), rankStartTime)), rankPerSecond, ((float)(rankTotalTuples - rankCountTuples))/rankPerSecond);
|
||||||
|
|
||||||
PQclear(resPlaces);
|
PQclear(resPlaces);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Finished rank
|
// Finished rank
|
||||||
printf("\r Done %i in %i @ %f per second - FINISHED \n\n", rankCountTuples, (int)(difftime(time(0), rankStartTime)), rankPerSecond);
|
printf("\r Done %i in %i @ %f per second - FINISHED \n\n", rankCountTuples, (int)(difftime(time(0), rankStartTime)), rankPerSecond);
|
||||||
|
|||||||
Reference in New Issue
Block a user