-
-
Save jwage/36b9da260fb7c841a953e924bb33d846 to your computer and use it in GitHub Desktop.
This is pseudo code to demonstrate a problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$rules = [ | |
[ | |
'id' => 1, | |
'expression' => 'x = 1 AND y = 2 AND userLogCount <= 5', | |
], | |
]; | |
$expressionLanguage = $container->get('expression_language'); | |
$context = [ | |
'x' => 1, | |
'y' => 2, | |
]; | |
$userId = 1; | |
foreach ($rules as $rule) { | |
$context['userLogCount'] = exec('SELECT COUNT(*) FROM reward_log WHERE ruleId = :ruleId AND userId = :userId', [ | |
'ruleId' => $rule['id'], | |
'userId' => $userId | |
]); | |
if ($expressionLanguage->evaluate($rule['expression'], $context)) { | |
$rule->insertLogEntry(); | |
$rule->executeAction(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the only way I can think of to avoid the problem by implementing some kind of atomic locking per userId using redis or something.