1
0
mirror of https://github.com/beestat/app.git synced 2025-07-09 03:04:07 -04:00

Fixed first sync producing errors due to settings overwriting each other.

This commit is contained in:
Jon Ziebell 2020-02-03 22:16:29 -05:00
parent 316e06fe21
commit 846eb9bb93
2 changed files with 11 additions and 11 deletions

View File

@ -1030,15 +1030,6 @@ final class cora {
$response_query_count = $this->response_query_counts[$index]; $response_query_count = $this->response_query_counts[$index];
$response_query_time = $this->response_query_times[$index]; $response_query_time = $this->response_query_times[$index];
// The data could be an integer, an XML string, an array, etc, but let's
// just always json_encode it to keep things simple and standard.
if($this->content_type_is_loggable() === true) {
$response_data = substr(json_encode($this->response_data[$index]), 0, 16384);
}
else {
$response_data = null;
}
$from_cache = $this->from_cache[$index]; $from_cache = $this->from_cache[$index];
$api_log_resource->create( $api_log_resource->create(
@ -1050,7 +1041,6 @@ final class cora {
'request_arguments' => preg_replace('/"(password)":".*"/', '"$1":"[removed]"', $request_arguments), 'request_arguments' => preg_replace('/"(password)":".*"/', '"$1":"[removed]"', $request_arguments),
'response_error_code' => $response_error_code, 'response_error_code' => $response_error_code,
'response_data' => null, // Can't store this; uses too much disk. 'response_data' => null, // Can't store this; uses too much disk.
// 'response_data' => preg_replace('/"(password)":".*"/', '"$1":"[removed]"', $response_data),
'response_time' => $response_time, 'response_time' => $response_time,
'response_query_count' => $response_query_count, 'response_query_count' => $response_query_count,
'response_query_time' => $response_query_time, 'response_query_time' => $response_query_time,

View File

@ -166,7 +166,14 @@ class user extends cora\crud {
} }
/** /**
* Set a setting on a user. * Set a setting on a user. This utilizes a lock because all settings are
* stored in a single JSON column. If multiple settings are updated rapidly,
* they will both read from the user at the same time, then run their
* updates sequentially and overwrite each other with old data.
*
* Don't release the lock either...wait for the database connection to close
* and the transaction to commit otherwise anything waiting will start and
* get old data.
* *
* @param string $key * @param string $key
* @param string $value * @param string $value
@ -174,6 +181,9 @@ class user extends cora\crud {
* @return array The new settings list. * @return array The new settings list.
*/ */
public function update_setting($key, $value) { public function update_setting($key, $value) {
$lock_name = 'user->update_setting(' . $this->session->get_user_id() . ')';
$this->database->get_lock($lock_name, 1);
$user = $this->get($this->session->get_user_id()); $user = $this->get($this->session->get_user_id());
if($user['settings'] === null) { if($user['settings'] === null) {
$settings = []; $settings = [];