Skip to content

Commit

Permalink
Finish 5.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlaefer committed Sep 6, 2019
2 parents bceb3a7 + 0720b3a commit 6ded556
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ module.exports = function (grunt) {
watch: {
sassStatic: {
files: ['webroot/css/src/**/*.scss'],
tasks: ['sass:static'],
tasks: ['dart-sass:static'],
},
sassTheme: {
files: ['plugins/Bota/webroot/css/src/**/*.scss'],
tasks: ['sass:theme'],
tasks: ['dart-sass:theme'],
},
},
postcss: {
Expand Down
4 changes: 3 additions & 1 deletion plugins/Bota/webroot/css/src/partials/_posting.scss
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@
// ------------------------------------- */

.postingform-smilies {
@extend .panel-form;
@extend .mb-3;

border: $input-border-width solid $input-border-color;

display: flex;
flex-wrap: wrap;
Expand Down
2 changes: 1 addition & 1 deletion src/Lib/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
$config = [
'Saito' =>
[
'v' => '5.3.1',
'v' => '5.3.2',
'saitoHomepage' => 'https://saito.siezi.com/'
]
];
Expand Down
51 changes: 30 additions & 21 deletions src/Model/Table/UserOnlineTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ class UserOnlineTable extends Table
use LogTrait;

/**
* Time in seconds until a user is considered offline
* Time in seconds until a user is considered offline.
*
* Default: 20 Minutes.
*
* @var int
*/
public $timeUntilOffline = 1200;
private $timeUntilOffline = 1200;

/**
* {@inheritDoc}
Expand All @@ -58,21 +60,16 @@ public function initialize(array $config)
]
);

$this->belongsTo(
'Users',
[
'foreignKey' => 'user_id'
]
);
$this->belongsTo('Users', ['foreignKey' => 'user_id']);
}

/**
* {@inheritDoc}
*/
public function validationDefault(Validator $validator)
{
/// uuid
$validator
//= uuid
->notEmpty('uuid')
->requirePresence('uuid')
->add(
Expand All @@ -88,6 +85,20 @@ public function validationDefault(Validator $validator)
return $validator;
}

/**
* Sets time in secondes until a user is considered offline.
*
* Adjust to sane values taking JS-frontend status ping time intervall into
* account, which also keeps the user online.
*
* @param int $period Time in seconds
* @return void
*/
public function setOnlinePeriod(int $period): void
{
$this->timeUntilOffline = $period;
}

/**
* Sets user with `$id` online
*
Expand All @@ -103,11 +114,9 @@ public function setOnline(string $id, bool $loggedIn): void
$user = $this->find()->where(['uuid' => $id])->first();

if ($user) {
// [Performance] Only hit database if timestamp is about to get outdated.
//
// Adjust to sane values taking JS-frontend status ping time
// intervall into account.
if ($user->get('time') < ($now - (int)($this->timeUntilOffline * 80 / 100))) {
/// [Performance] Only hit database if timestamp is about to get outdated.
$updateIfOlderThan = $now - (int)$this->timeUntilOffline * 0.75;
if ($user->get('time') < $updateIfOlderThan) {
$user->set('time', $now);
$this->save($user);
}
Expand Down Expand Up @@ -142,7 +151,7 @@ public function setOnline(string $id, bool $loggedIn): void
// in this particular situation. *knocks on wood*
if ($e->getCode() == 23000 && strstr($e->getMessage(), 'uuid')) {
$this->log(
'Cought duplicate "uuid" key exception in UserOnline::setOnline.',
sprintf('Cought duplicate uuid-key %s exception in UserOnline::setOnline.', $id),
LogLevel::INFO,
'saito.info'
);
Expand Down Expand Up @@ -193,22 +202,22 @@ public function getLoggedIn(): Query
}

/**
* Removes users which weren't online $timeDiff seconds
* Removes users which weren't online $timeDiff seconds.
*
* @return void
*/
public function gc(): void
{
$this->deleteAll(['time <' => time() - ($this->timeUntilOffline)]);
$this->deleteAll(['time <' => time() - $this->timeUntilOffline]);
}

/**
* Shortens a string to fit in the uuid table-field
* Shortens a string to fit in the uuid table-field.
*
* @param string $id string
* @return string
* @param string $id The string to shorten.
* @return string The shoretened string.
*/
protected function getShortendedId(string $id)
protected function getShortendedId(string $id): string
{
return substr($id, 0, 32);
}
Expand Down
5 changes: 2 additions & 3 deletions tests/TestCase/Model/Table/UserOnlineTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

class UserOnlineTableTest extends SaitoTableTestCase
{

public $tableClass = 'UserOnline';

public $fixtures = [
Expand Down Expand Up @@ -115,7 +114,7 @@ public function testSetOnlineSuccess()

//// *** Second 2 *** - Forces an table update.
sleep(1);
$this->Table->timeUntilOffline = 1;
$this->Table->setOnlinePeriod(1);
$this->Table->gc();

/// update anonymous user after time
Expand Down Expand Up @@ -179,7 +178,7 @@ public function testSetOffline()

public function testDeleteOutdated()
{
$this->Table->timeUntilOffline = 1;
$this->Table->setOnlinePeriod(1);

/// add new user
$_userId = 5;
Expand Down

0 comments on commit 6ded556

Please sign in to comment.