Commit 10c405f3 authored by Raúl Marín's avatar Raúl Marín

Revert "Internal cache now persists until the end of the transaction"

This reverts commit 3ced96fc.

References #4674
Closes https://github.com/postgis/postgis/pull/560
parent 943cda08
Pipeline #142488006 passed with stage
in 29 minutes and 5 seconds
......@@ -4,7 +4,7 @@ PostGIS 3.1.0XXXX
Only tickets not included in 3.1.0alpha1
* Breaking changes *
- #4674, Internal cache now persists until the end of the transaction (Raúl Marín)
-
* New features *
- #4656, Cast a geojson_text::geometry for implicit GeoJSON ingestion (Raúl Marín)
......
......@@ -62,23 +62,13 @@ typedef struct {
/**
* Utility function to read the upper memory context off a function call
* info data.
* This used to return flinfo->fn_mcxt (the function memory context) but that has the issue
* that is cleaned up once the function is finished, which on pure SQL functions (like ST_AsGML(geometry))
* is an issue as the cache will die after every _ST_AsGML call (thus being worthless).
* Instead we use CurTransactionContext which will live until the end of the transaction
*/
MemoryContext
PostgisCacheContext(FunctionCallInfo fcinfo)
{
return CurTransactionContext;
}
static GenericCacheCollection *internal_cache = NULL;
static void
PostgisResetInternalCache(void *v)
{
internal_cache = NULL;
if (!fcinfo->flinfo)
elog(ERROR, "%s: Could not find upper context", __func__);
return fcinfo->flinfo->fn_mcxt;
}
/**
......@@ -88,18 +78,17 @@ PostgisResetInternalCache(void *v)
static GenericCacheCollection *
GetGenericCacheCollection(FunctionCallInfo fcinfo)
{
GenericCacheCollection *internal_cache;
if (!fcinfo->flinfo)
elog(ERROR, "%s: Could not find upper context", __func__);
internal_cache = fcinfo->flinfo->fn_extra;
if (!internal_cache)
{
internal_cache = MemoryContextAlloc(PostgisCacheContext(fcinfo), sizeof(GenericCacheCollection));
memset(internal_cache, 0, sizeof(GenericCacheCollection));
MemoryContextCallback *cb =
MemoryContextAlloc(PostgisCacheContext(fcinfo), sizeof(MemoryContextCallback));
cb->func = PostgisResetInternalCache;
cb->arg = NULL;
MemoryContextRegisterResetCallback(PostgisCacheContext(fcinfo), cb);
internal_cache = MemoryContextAllocZero(PostgisCacheContext(fcinfo), sizeof(GenericCacheCollection));
fcinfo->flinfo->fn_extra = internal_cache;
}
return internal_cache;
}
......
......@@ -658,8 +658,10 @@ Datum parse_WKT_lwgeom(PG_FUNCTION_ARGS)
/* Unwrap the PgSQL text type into a cstring */
wkt = text_to_cstring(wkt_text);
/* Now we call over to the geometry_in function */
result = DirectFunctionCall1(LWGEOM_in, CStringGetDatum(wkt));
/* Now we call over to the geometry_in function
* We need to initialize the fcinfo since cache might be used
*/
result = CallerFInfoFunctionCall1(LWGEOM_in, fcinfo->flinfo, InvalidOid, CStringGetDatum(wkt));
/* Return null on null */
if ( ! result )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment