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

use prepared load statements #44

Merged
merged 3 commits into from
Jan 18, 2017

Conversation

oqq
Copy link
Member

@oqq oqq commented Jan 18, 2017

Currently the queries in aggregate load methods from event stores builds queries and recreate this for batch requests.

This PR changes this behavior and implements prepared statements. The PdoStreamIterator has only to change the values for fromNumber and limit without have to know how to queries should be builded.

@@ -78,7 +76,6 @@ public function __construct(
PDO $connection,
PDOStatement $statement,
MessageFactory $messageFactory,
array $sql,
?int $batchSize,
int $fromNumber,
int $count,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is bool forward still needed then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok

{
$limit = $this->count < ($this->batchSize * ($this->batchPosition + 1))
? $this->count - ($this->batchSize * $this->batchPosition)
: $this->batchSize;

if ($this->forward) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see you removed forward

$sql['where'][] = "metadata ->> '$field' $operator $value";
} else {
$sql['where'][] = "metadata ->> '$field' $operator '$value'";
$where[] = "metadata->'$field' $operator '".var_export($value, true)."'";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

metadata ->> instead of metadata ->

see: https://www.postgresql.org/docs/9.3/static/functions-json.html

-> means: Get JSON object field
->> means: Get JSON object field as text

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about that, but mysql declares

->> as shortcut for JSON_UNQUOTE(JSON_EXTRACT()), and
-> as shortcut for JSON_EXTRACT()

So ->> is always an extra step. With -> all tests passes. Maybe Postgre is fine with. Should we add an extra step?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, ok when it works

$value = var_export($value, true);
} elseif (is_string($value)) {
$value = $this->connection->quote($value);
$where[] = "metadata->\"$.$field\" $operator ".var_export($value, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be metadata->> to unquote.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Than it would also match 'true' === true. Right?

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.009%) to 98.918% when pulling dbb9a70 on oqq:improvements/prepared_load_statements into 51eed08 on prooph:master.

@prolic prolic self-assigned this Jan 18, 2017
@prolic prolic merged commit de95a0f into prooph:master Jan 18, 2017
@prolic
Copy link
Member

prolic commented Jan 18, 2017

great work! thx! 👍

@oqq oqq deleted the improvements/prepared_load_statements branch January 18, 2017 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants