Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F785082
D447.id1174.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Feb 12, 12:58 AM
Size
1 KB
Mime Type
text/x-diff
Expires
Thu, Feb 13, 12:58 AM (11 h, 18 m)
Engine
blob
Format
Raw Data
Handle
564143
Attached To
D447: INP-1842 - Cache user primary group detection during Checkout
D447.id1174.diff
View Options
Index: branches/5.2.x/core/units/helpers/user_helper.php
===================================================================
--- branches/5.2.x/core/units/helpers/user_helper.php
+++ branches/5.2.x/core/units/helpers/user_helper.php
@@ -722,4 +722,32 @@
return $object->Update() ? '' : 'restore_impossible';
}
+
+ /**
+ * Returns user's primary group.
+ *
+ * @param integer $user_id User ID.
+ *
+ * @return integer
+ */
+ public function getPrimaryGroup($user_id)
+ {
+ if ( $user_id <= 0 ) {
+ return $this->Application->ConfigValue('User_LoggedInGroup');
+ }
+
+ $cache_key = 'user' . $user_id . '_primary_group[%UIDSerial:' . $user_id . '%]';
+ $cache_value = $this->Application->getCache($cache_key);
+
+ if ( $cache_value === false ) {
+ $sql = 'SELECT PrimaryGroupId
+ FROM ' . TABLE_PREFIX . 'Users
+ WHERE PortalUserId = ' . $user_id;
+ $cache_value = $this->Conn->GetOne($sql);
+ $this->Application->setCache($cache_key, $cache_value);
+ }
+
+ return $cache_value;
+ }
+
}
Index: branches/5.2.x/core/units/users/users_event_handler.php
===================================================================
--- branches/5.2.x/core/units/users/users_event_handler.php
+++ branches/5.2.x/core/units/users/users_event_handler.php
@@ -1665,6 +1665,12 @@
WHERE PortalUserId IN (' . implode(',', $user_ids) . ')';
$this->Conn->Query($sql);
+ foreach ( $user_ids as $user_id ) {
+ $this->Application->incrementCacheSerial('u', $user_id);
+ }
+
+ $this->Application->incrementCacheSerial('u');
+
$sql = 'SELECT PortalUserId
FROM ' . $table_name . '
WHERE (GroupId = ' . $primary_group_id . ') AND (PortalUserId IN (' . implode(',', $user_ids) . '))';
Event Timeline
Log In to Comment