Merge pull request #7651 from owncloud/close-session-faster-master
Close session faster
This commit is contained in:
commit
8a81df0f2c
|
@ -1,10 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
// Init owncloud
|
|
||||||
|
|
||||||
|
|
||||||
OCP\JSON::checkLoggedIn();
|
OCP\JSON::checkLoggedIn();
|
||||||
OCP\JSON::callCheck();
|
OCP\JSON::callCheck();
|
||||||
|
\OC::$session->close();
|
||||||
|
|
||||||
|
|
||||||
// Get data
|
// Get data
|
||||||
$dir = stripslashes($_POST["dir"]);
|
$dir = stripslashes($_POST["dir"]);
|
||||||
|
|
|
@ -29,6 +29,7 @@ $RUNTIME_APPTYPES=array('filesystem');
|
||||||
|
|
||||||
// Check if we are a user
|
// Check if we are a user
|
||||||
OCP\User::checkLoggedIn();
|
OCP\User::checkLoggedIn();
|
||||||
|
\OC::$session->close();
|
||||||
|
|
||||||
$files = $_GET["files"];
|
$files = $_GET["files"];
|
||||||
$dir = $_GET["dir"];
|
$dir = $_GET["dir"];
|
||||||
|
|
|
@ -10,6 +10,7 @@ if (isset($_GET['dir'])) {
|
||||||
}
|
}
|
||||||
|
|
||||||
OCP\JSON::checkLoggedIn();
|
OCP\JSON::checkLoggedIn();
|
||||||
|
\OC::$session->close();
|
||||||
|
|
||||||
// send back json
|
// send back json
|
||||||
OCP\JSON::success(array('data' => \OCA\Files\Helper::buildFileStorageStatistics($dir)));
|
OCP\JSON::success(array('data' => \OCA\Files\Helper::buildFileStorageStatistics($dir)));
|
||||||
|
|
|
@ -7,6 +7,7 @@ $RUNTIME_APPTYPES=array('filesystem');
|
||||||
|
|
||||||
|
|
||||||
OCP\JSON::checkLoggedIn();
|
OCP\JSON::checkLoggedIn();
|
||||||
|
\OC::$session->close();
|
||||||
|
|
||||||
// Load the files
|
// Load the files
|
||||||
$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
|
$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
\OC::$session->close();
|
||||||
|
|
||||||
print OC_Helper::mimetypeIcon($_GET['mime']);
|
print OC_Helper::mimetypeIcon($_GET['mime']);
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
// Init owncloud
|
|
||||||
|
|
||||||
|
|
||||||
OCP\JSON::checkLoggedIn();
|
OCP\JSON::checkLoggedIn();
|
||||||
OCP\JSON::callCheck();
|
OCP\JSON::callCheck();
|
||||||
|
\OC::$session->close();
|
||||||
|
|
||||||
// Get data
|
// Get data
|
||||||
$dir = stripslashes($_POST["dir"]);
|
$dir = stripslashes($_POST["dir"]);
|
||||||
|
|
|
@ -7,7 +7,8 @@ if(!OC_User::isLoggedIn()) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
session_write_close();
|
\OC::$session->close();
|
||||||
|
|
||||||
// Get the params
|
// Get the params
|
||||||
$dir = isset( $_REQUEST['dir'] ) ? '/'.trim($_REQUEST['dir'], '/\\') : '';
|
$dir = isset( $_REQUEST['dir'] ) ? '/'.trim($_REQUEST['dir'], '/\\') : '';
|
||||||
$filename = isset( $_REQUEST['filename'] ) ? trim($_REQUEST['filename'], '/\\') : '';
|
$filename = isset( $_REQUEST['filename'] ) ? trim($_REQUEST['filename'], '/\\') : '';
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
OCP\JSON::checkLoggedIn();
|
OCP\JSON::checkLoggedIn();
|
||||||
OCP\JSON::callCheck();
|
OCP\JSON::callCheck();
|
||||||
|
\OC::$session->close();
|
||||||
|
|
||||||
// Get the params
|
// Get the params
|
||||||
$dir = isset( $_POST['dir'] ) ? stripslashes($_POST['dir']) : '';
|
$dir = isset( $_POST['dir'] ) ? stripslashes($_POST['dir']) : '';
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
$RUNTIME_APPTYPES = array('filesystem');
|
$RUNTIME_APPTYPES = array('filesystem');
|
||||||
|
|
||||||
OCP\JSON::checkLoggedIn();
|
OCP\JSON::checkLoggedIn();
|
||||||
|
\OC::$session->close();
|
||||||
|
|
||||||
// Load the files
|
// Load the files
|
||||||
$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
|
$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
OCP\JSON::checkLoggedIn();
|
OCP\JSON::checkLoggedIn();
|
||||||
OCP\JSON::callCheck();
|
OCP\JSON::callCheck();
|
||||||
|
\OC::$session->close();
|
||||||
|
|
||||||
$files = new \OCA\Files\App(
|
$files = new \OCA\Files\App(
|
||||||
\OC\Files\Filesystem::getView(),
|
\OC\Files\Filesystem::getView(),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
set_time_limit(0); //scanning can take ages
|
set_time_limit(0); //scanning can take ages
|
||||||
session_write_close();
|
\OC::$session->close();
|
||||||
|
|
||||||
$force = (isset($_GET['force']) and ($_GET['force'] === 'true'));
|
$force = (isset($_GET['force']) and ($_GET['force'] === 'true'));
|
||||||
$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
|
$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
|
||||||
|
|
|
@ -58,6 +58,7 @@ if (empty($_POST['dirToken'])) {
|
||||||
|
|
||||||
|
|
||||||
OCP\JSON::callCheck();
|
OCP\JSON::callCheck();
|
||||||
|
\OC::$session->close();
|
||||||
|
|
||||||
|
|
||||||
// get array with current storage stats (e.g. max file size)
|
// get array with current storage stats (e.g. max file size)
|
||||||
|
|
|
@ -367,9 +367,14 @@ class Helper {
|
||||||
$post = 0;
|
$post = 0;
|
||||||
if(count($_POST) > 0) {
|
if(count($_POST) > 0) {
|
||||||
$post = 1;
|
$post = 1;
|
||||||
}
|
}
|
||||||
header('Location: ' . $location . '?p=' . $post . '&errorCode=' . $errorCode);
|
|
||||||
exit();
|
if(defined('PHPUNIT_RUN') and PHPUNIT_RUN) {
|
||||||
|
throw new \Exception("Encryption error: $errorCode");
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Location: ' . $location . '?p=' . $post . '&errorCode=' . $errorCode);
|
||||||
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
2
cron.php
2
cron.php
|
@ -48,7 +48,7 @@ try {
|
||||||
|
|
||||||
require_once 'lib/base.php';
|
require_once 'lib/base.php';
|
||||||
|
|
||||||
session_write_close();
|
\OC::$session->close();
|
||||||
|
|
||||||
$logger = \OC_Log::$object;
|
$logger = \OC_Log::$object;
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,20 @@ class OC_Connector_Sabre_Auth extends Sabre_DAV_Auth_Backend_AbstractBasic {
|
||||||
*/
|
*/
|
||||||
public function authenticate(Sabre_DAV_Server $server, $realm) {
|
public function authenticate(Sabre_DAV_Server $server, $realm) {
|
||||||
|
|
||||||
|
$result = $this->auth($server, $realm);
|
||||||
|
|
||||||
|
// close the session - right after authentication there is not need to write to the session any more
|
||||||
|
\OC::$session->close();
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Sabre_DAV_Server $server
|
||||||
|
* @param $realm
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function auth(Sabre_DAV_Server $server, $realm) {
|
||||||
if (OC_User::handleApacheAuth() || OC_User::isLoggedIn()) {
|
if (OC_User::handleApacheAuth() || OC_User::isLoggedIn()) {
|
||||||
$user = OC_User::getUser();
|
$user = OC_User::getUser();
|
||||||
OC_Util::setupFS($user);
|
OC_Util::setupFS($user);
|
||||||
|
@ -81,5 +95,5 @@ class OC_Connector_Sabre_Auth extends Sabre_DAV_Auth_Backend_AbstractBasic {
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::authenticate($server, $realm);
|
return parent::authenticate($server, $realm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,7 @@ class Internal extends Memory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __destruct() {
|
public function __destruct() {
|
||||||
$_SESSION = array_merge($_SESSION, $this->data);
|
$this->close();
|
||||||
session_write_close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,4 +46,15 @@ class Internal extends Memory {
|
||||||
@session_start();
|
@session_start();
|
||||||
$this->data = $_SESSION = array();
|
$this->data = $_SESSION = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function close() {
|
||||||
|
$_SESSION = array_merge($_SESSION, $this->data);
|
||||||
|
session_write_close();
|
||||||
|
|
||||||
|
parent::close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function reopen() {
|
||||||
|
throw new \Exception('The session cannot be reopened - reopen() is ony to be used in unit testing.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ class Memory extends Session {
|
||||||
* @param integer $value
|
* @param integer $value
|
||||||
*/
|
*/
|
||||||
public function set($key, $value) {
|
public function set($key, $value) {
|
||||||
|
$this->validateSession();
|
||||||
$this->data[$key] = $value;
|
$this->data[$key] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,10 +55,29 @@ class Memory extends Session {
|
||||||
* @param string $key
|
* @param string $key
|
||||||
*/
|
*/
|
||||||
public function remove($key) {
|
public function remove($key) {
|
||||||
|
$this->validateSession();
|
||||||
unset($this->data[$key]);
|
unset($this->data[$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clear() {
|
public function clear() {
|
||||||
$this->data = array();
|
$this->data = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function for PHPUnit execution - don't use in non-test code
|
||||||
|
*/
|
||||||
|
public function reopen() {
|
||||||
|
$this->sessionClosed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In case the session has already been locked an exception will be thrown
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
private function validateSession() {
|
||||||
|
if ($this->sessionClosed) {
|
||||||
|
throw new \Exception('Session has been closed - no further changes to the session as allowed');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,11 @@ use OCP\ISession;
|
||||||
|
|
||||||
abstract class Session implements \ArrayAccess, ISession {
|
abstract class Session implements \ArrayAccess, ISession {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $sessionClosed = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $name serves as a namespace for the session keys
|
* $name serves as a namespace for the session keys
|
||||||
*
|
*
|
||||||
|
@ -49,4 +54,11 @@ abstract class Session implements \ArrayAccess, ISession {
|
||||||
public function offsetUnset($offset) {
|
public function offsetUnset($offset) {
|
||||||
$this->remove($offset);
|
$this->remove($offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the session and release the lock
|
||||||
|
*/
|
||||||
|
public function close() {
|
||||||
|
$this->sessionClosed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,4 +75,9 @@ interface ISession {
|
||||||
*/
|
*/
|
||||||
public function clear();
|
public function clear();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the session and release the lock
|
||||||
|
*/
|
||||||
|
public function close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
</whitelist>
|
</whitelist>
|
||||||
</filter>
|
</filter>
|
||||||
<listeners>
|
<listeners>
|
||||||
|
<listener class="StartSessionListener" file="startsessionlistener.php" />
|
||||||
<listener class="TestCleanupListener" file="testcleanuplistener.php">
|
<listener class="TestCleanupListener" file="testcleanuplistener.php">
|
||||||
<arguments>
|
<arguments>
|
||||||
<string>detail</string>
|
<string>detail</string>
|
||||||
|
|
|
@ -29,4 +29,7 @@
|
||||||
</exclude>
|
</exclude>
|
||||||
</whitelist>
|
</whitelist>
|
||||||
</filter>
|
</filter>
|
||||||
|
<listeners>
|
||||||
|
<listener class="StartSessionListener" file="startsessionlistener.php" />
|
||||||
|
</listeners>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com>
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later.
|
||||||
|
* See the COPYING-README file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts a new session before each test execution
|
||||||
|
*/
|
||||||
|
class StartSessionListener implements PHPUnit_Framework_TestListener {
|
||||||
|
|
||||||
|
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function startTest(PHPUnit_Framework_Test $test) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function endTest(PHPUnit_Framework_Test $test, $time) {
|
||||||
|
// reopen the session - only allowed for memory session
|
||||||
|
if (\OC::$session instanceof \OC\Session\Memory) {
|
||||||
|
/** @var $session \OC\Session\Memory */
|
||||||
|
$session = \OC::$session;
|
||||||
|
$session->reopen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue