diff options
author | randomdan <randomdan@localhost> | 2011-11-25 20:10:37 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2011-11-25 20:10:37 +0000 |
commit | 869011272b8886b7097ad43835373d12c8202397 (patch) | |
tree | 8dffb8306f8cf5974fdb73f3132e8be8602d71e6 | |
parent | Remove the need to implement loadComplete which is empty in most cases (diff) | |
download | project2-869011272b8886b7097ad43835373d12c8202397.tar.bz2 project2-869011272b8886b7097ad43835373d12c8202397.tar.xz project2-869011272b8886b7097ad43835373d12c8202397.zip |
Don't needlessly write empty sessions
-rw-r--r-- | project2/cgi/cgiAppEngine.cpp | 9 | ||||
-rw-r--r-- | project2/common/session.cpp | 6 | ||||
-rw-r--r-- | project2/common/session.h | 1 | ||||
-rw-r--r-- | project2/common/sessionContainer.cpp | 11 | ||||
-rw-r--r-- | project2/common/sessionContainer.h | 1 | ||||
-rw-r--r-- | project2/json/couchSession.cpp | 2 | ||||
-rw-r--r-- | project2/xml/sessionXml.cpp | 2 |
7 files changed, 19 insertions, 13 deletions
diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index 37ae19c..45ccd95 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -49,6 +49,7 @@ CgiApplicationEngine::env() const void CgiApplicationEngine::process() const { + bool sessionEmpty = cursession->Empty(); startTime = boost::date_time::microsec_clock<boost::posix_time::ptime>::universal_time(); bool triedNotFound = false; bool triedOnError = false; @@ -85,8 +86,11 @@ CgiApplicationEngine::process() const addEnvData(currentStage.get<3>().get()); } HttpHeaderPtr header = rs->getHeader(); - header->setCookie(cgicc::HTTPCookie(SESSIONID, cursession->ID.str(), "Session ID", - _env->getServerName().substr(_env->getServerName().find(".")), env()->sessionTimeOut, "/", false)); + if (!sessionEmpty || !cursession->Empty()) { + sessionsContainer->SaveSession(cursession); + header->setCookie(cgicc::HTTPCookie(SESSIONID, cursession->ID.str(), "Session ID", + _env->getServerName().substr(_env->getServerName().find(".")), env()->sessionTimeOut, "/", false)); + } header->render(IO); if (currentStage.get<2>()) { TransformSourcePtr ts = currentStage.get<2>(); @@ -101,7 +105,6 @@ CgiApplicationEngine::process() const delete ddd; } } - sessionsContainer->SaveSession(cursession); } CgiApplicationEngine::Stage::Stage(const CgiEnvironment * env) : diff --git a/project2/common/session.cpp b/project2/common/session.cpp index fcfd3ca..9736c4d 100644 --- a/project2/common/session.cpp +++ b/project2/common/session.cpp @@ -23,6 +23,12 @@ Session::ExpiryTime() const return expires; } +bool +Session::Empty() const +{ + return vars.empty(); +} + VariableType Session::GetValue(const Glib::ustring & name) const { diff --git a/project2/common/session.h b/project2/common/session.h index 6aba83c..267dc51 100644 --- a/project2/common/session.h +++ b/project2/common/session.h @@ -24,6 +24,7 @@ class Session : public virtual IntrusivePtrBase { void ForeachValue(const SVH &) const; void SetValue(const Glib::ustring & name, const VariableType & value); void ClearValue(const Glib::ustring & name); + bool Empty() const; time_t ExpiryTime() const; const UUID ID; diff --git a/project2/common/sessionContainer.cpp b/project2/common/sessionContainer.cpp index 82b7ca8..f4d7cd4 100644 --- a/project2/common/sessionContainer.cpp +++ b/project2/common/sessionContainer.cpp @@ -13,14 +13,11 @@ SessionContainer::~SessionContainer() SessionPtr SessionContainer::GetSession(const UUID & id) const { - SessionPtr s = getSession(id); + SessionPtr s; + if (id.is_nil() || !(s = getSession(id))) { + s = new Session(UUID::generate_random()); + } s->ExpiryTime(time(NULL) + Environment::getCurrent()->sessionTimeOut); return s; } -SessionPtr -SessionContainer::newSession() const -{ - return new Session(UUID::generate_random()); -} - diff --git a/project2/common/sessionContainer.h b/project2/common/sessionContainer.h index 1ee7689..ffbc5ed 100644 --- a/project2/common/sessionContainer.h +++ b/project2/common/sessionContainer.h @@ -15,7 +15,6 @@ class SessionContainer : public IntrusivePtrBase { protected: virtual SessionPtr getSession(const UUID & sid) const = 0; - SessionPtr newSession() const; }; typedef boost::intrusive_ptr<SessionContainer> SessionContainerPtr; diff --git a/project2/json/couchSession.cpp b/project2/json/couchSession.cpp index c6a15c0..35650f2 100644 --- a/project2/json/couchSession.cpp +++ b/project2/json/couchSession.cpp @@ -32,7 +32,7 @@ class CouchSessionContainer : public SessionContainer { } catch (...) { } - return newSession(); + return NULL; } virtual void SaveSession(SessionPtr s) const { diff --git a/project2/xml/sessionXml.cpp b/project2/xml/sessionXml.cpp index 3fb925f..834c461 100644 --- a/project2/xml/sessionXml.cpp +++ b/project2/xml/sessionXml.cpp @@ -105,6 +105,6 @@ SessionContainerXml::getSession(const UUID & sid) const } catch (...) { } - return newSession(); + return NULL; } |