Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
3ace12ca
Commit
3ace12ca
authored
18 years ago
by
Dries Buytaert
Browse files
Options
Downloads
Patches
Plain Diff
- Patch #node/76931 by Robert: improved performance of Drupal's session handling.
parent
9f8abbcc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
includes/bootstrap.inc
+14
-0
14 additions, 0 deletions
includes/bootstrap.inc
includes/session.inc
+23
-19
23 additions, 19 deletions
includes/session.inc
with
37 additions
and
19 deletions
includes/bootstrap.inc
+
14
−
0
View file @
3ace12ca
...
@@ -610,6 +610,20 @@ function drupal_is_denied($type, $mask) {
...
@@ -610,6 +610,20 @@ function drupal_is_denied($type, $mask) {
return
$deny
&&
!
$allow
;
return
$deny
&&
!
$allow
;
}
}
/**
* Generates a default annonymous $user object.
*
* @return Object - the user object.
*/
function
drupal_anonymous_user
()
{
$user
=
new
stdClass
();
$user
->
uid
=
0
;
$user
->
hostname
=
$_SERVER
[
'REMOTE_ADDR'
];
$user
->
roles
=
array
();
$user
->
roles
[
DRUPAL_ANONYMOUS_RID
]
=
'anonymous user'
;
return
$user
;
}
/**
/**
* A string describing a phase of Drupal to load. Each phase adds to the
* A string describing a phase of Drupal to load. Each phase adds to the
* previous one, so invoking a later phase automatically runs the earlier
* previous one, so invoking a later phase automatically runs the earlier
...
...
This diff is collapsed.
Click to expand it.
includes/session.inc
+
23
−
19
View file @
3ace12ca
...
@@ -17,39 +17,44 @@ function sess_close() {
...
@@ -17,39 +17,44 @@ function sess_close() {
function
sess_read
(
$key
)
{
function
sess_read
(
$key
)
{
global
$user
;
global
$user
;
// retrieve data for a $user object
// Handle the case of first time visitors and clients that don't store cookies (eg. web crawlers).
$result
=
db_query
(
"SELECT sid FROM
{
sessions
}
WHERE sid = '%s'"
,
$key
);
if
(
!
isset
(
$_COOKIE
[
session_name
()]))
{
if
(
!
db_num_rows
(
$result
))
{
$user
=
drupal_anonymous_user
();
$result
=
db_query
(
"SELECT u.* FROM
{
users
}
u WHERE u.uid = 0"
);
return
''
;
}
else
{
$result
=
db_query
(
"SELECT u.*, s.* FROM
{
users
}
u INNER JOIN
{
sessions
}
s ON u.uid = s.uid WHERE s.sid = '%s'"
,
$key
);
}
}
// Build $user object:
// Otherwise, if the session is still active, we have a record of the client's session in the database.
$user
=
db_fetch_object
(
$result
);
$user
=
db_fetch_object
(
db_query
(
"SELECT u.*, s.* FROM
{
users
}
u INNER JOIN
{
sessions
}
s ON u.uid = s.uid WHERE s.sid = '%s'"
,
$key
));
$user
=
drupal_unpack
(
$user
);
//
Add roles element to $
user
:
//
We found the client's session record and they are an authenticated
user
$user
->
roles
=
array
();
if
(
$user
->
uid
>
0
)
{
if
(
$user
->
uid
)
{
// This is done to unserialize the data member of $user
$user
->
roles
[
DRUPAL_AUTHENTICATED_RID
]
=
'authenticated
user
'
;
$user
=
drupal_unpack
(
$
user
)
;
// Add roles element to $user
$user
->
roles
=
array
();
$user
->
roles
[
DRUPAL_AUTHENTICATED_RID
]
=
'authenticated user'
;
$result
=
db_query
(
"SELECT r.rid, r.name FROM
{
role
}
r INNER JOIN
{
users_roles
}
ur ON ur.rid = r.rid WHERE ur.uid = %d"
,
$user
->
uid
);
$result
=
db_query
(
"SELECT r.rid, r.name FROM
{
role
}
r INNER JOIN
{
users_roles
}
ur ON ur.rid = r.rid WHERE ur.uid = %d"
,
$user
->
uid
);
while
(
$role
=
db_fetch_object
(
$result
))
{
while
(
$role
=
db_fetch_object
(
$result
))
{
$user
->
roles
[
$role
->
rid
]
=
$role
->
name
;
$user
->
roles
[
$role
->
rid
]
=
$role
->
name
;
}
}
}
}
else
{
// We didn't find the client's record (session has expired), or they are an anonymous user.
$user
->
roles
[
DRUPAL_ANONYMOUS_RID
]
=
'anonymous user'
;
else
{
$user
=
drupal_anonymous_user
();
}
}
return
!
empty
(
$user
->
session
)
?
$user
->
session
:
''
;
return
$user
->
session
;
}
}
function
sess_write
(
$key
,
$value
)
{
function
sess_write
(
$key
,
$value
)
{
global
$user
;
global
$user
;
// If the client doesn't have a session, and one isn't being created ($value), do nothing.
if
(
empty
(
$_COOKIE
[
session_name
()])
&&
empty
(
$value
))
{
return
TRUE
;
}
$result
=
db_query
(
"SELECT sid FROM
{
sessions
}
WHERE sid = '%s'"
,
$key
);
$result
=
db_query
(
"SELECT sid FROM
{
sessions
}
WHERE sid = '%s'"
,
$key
);
if
(
!
db_num_rows
(
$result
))
{
if
(
!
db_num_rows
(
$result
))
{
...
@@ -87,5 +92,4 @@ function sess_gc($lifetime) {
...
@@ -87,5 +92,4 @@ function sess_gc($lifetime) {
db_query
(
"DELETE FROM
{
sessions
}
WHERE timestamp < %d"
,
time
()
-
$lifetime
);
db_query
(
"DELETE FROM
{
sessions
}
WHERE timestamp < %d"
,
time
()
-
$lifetime
);
return
TRUE
;
return
TRUE
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment