Lack of interest Reduce the query count of the members profile area


Well-known member
The members profile area is the area that concerns me the most for performance. Even without additional plugins, the query count for this area is fairly high

The members area (without any plugins) has a base query count of 17 (+ 1 or 2, since some are cached)

This seems a bit too high, especially since many plugins like to abuse this area

Just one or two plugins can quickly bump the query count over the 20 mark (I've seen some plugins add more than 5 queries to this area)

Is it possible to reduce the base query count of the members area, after all, this is pretty much an ajax area, in which all of the tabbed data will be retrieved at the time of clicking it.

XenForo only really needs to grab

User (includes Last Activity, Joined, Likes Received, Trophy Points)
Profile posts

These are all of the models used that retrieve data via queries in the members profile area:

+1 Query via getUserOrError
$user = $this->getHelper('UserProfile')->assertUserProfileValidAndViewable($userId, $userFetchOptions);

+1 Query via getFollowingDenormalizedValue
$user['following'] = $userModel->getFollowingDenormalizedValue($user['user_id']);
        $userModel->updateFollowingDenormalizedValue($user['user_id'], $user['following']);
+1 Query via getUserFields
$customFields = $fieldModel->prepareUserFields($fieldModel->getUserFields(
        array('profileView' => true),
        array('valueUserId' => $user['user_id'])

+1 Query via getFollowedUserProfiles   
$following = $userModel->getFollowedUserProfiles($userId, $followingToShowCount, 'RAND()');
+1 Query via countProfilePostsForUserId
$totalProfilePosts = $profilePostModel->countProfilePostsForUserId($userId, $profilePostConditions);

+1 Query via getProfilePostsForUserId
$profilePosts = $profilePostModel->getProfilePostsForUserId($userId, $profilePostConditions, $profilePostFetchOptions);

+1 Query addProfilePostCommentsToProfilePosts
$profilePosts = $profilePostModel->addProfilePostCommentsToProfilePosts($profilePosts, array(
        'join' => XenForo_Model_ProfilePost::FETCH_COMMENT_USER

+1 Query from countUsersFollowingUserId   
$followersCount = $userModel->countUsersFollowingUserId($userId);

+1 Query from getUsersFollowingUserId
$followers = $userModel->getUsersFollowingUserId($userId, 6, 'RAND()');

+1 Query from countWarningsByUser
$warningCount = $this->getModelFromCache('XenForo_Model_Warning')->countWarningsByUser($user['user_id']);
That's 10 queries (+ 7 from base) = 17 (approximately, I'm not sure if I missed any)

Can XenForo combine some of these queries, it seems sensible to combine the user queries/follows/warnings as one group and profile posts as another (potentially reducing the query count by 4 or 5)
Last edited: