Skip to content

Make ResultSet serializable so cached queries can be executed - #347

Open
andrii-pukhalevych wants to merge 2 commits into
cakephp:5.xfrom
andrii-pukhalevych:cache-with-execuded-query
Open

Make ResultSet serializable so cached queries can be executed#347
andrii-pukhalevych wants to merge 2 commits into
cakephp:5.xfrom
andrii-pukhalevych:cache-with-execuded-query

Conversation

@andrii-pukhalevych

Copy link
Copy Markdown
Contributor

Calling Query::cache() and then executing the query always threw "Serialization of 'CurlHandle' is not allowed", which made query result caching unusable with FileEngine.

Query::all() hands the decorated ResultSet to QueryCacher::store(), and ResultSet keeps the query that produced it in $queryObject. From there the whole connection is reachable:

  ResultSet::$queryObject      -> Query
  Query::$_repository          -> Index
  Index::$_connection          -> Datasource\Connection
  Connection::$_client         -> Elastica\Client
  Elastica\Client::$_transport -> Transport
  Transport::$client           -> Transport\Client\Curl
  Curl::$curl                  -> CurlHandle

Add __serialize()/__unserialize() that leave the query object out.
The decorated Elastica\ResultSet is kept whole rather than flattened to documents, so getTotalHits(), getAggregations(), getSuggests(), getMaxScore(), getTotalTime() and hasTimedOut() still answer correctly after a cache round trip. Since unserialize() does not run the constructor, __unserialize() calls parent::__construct() to set up the decorated iterator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant