presence: Use the narrow user cache.

These two endpoints make up ~85% of requests to Zulip servers; since
presence is also a performance-critical endpoint, having them share
the same cache increases how hot it stays in memcached, in addition to
making the presence endpoint faster.

This comes at the very slightly cost of one extra field.  Checks
for the `is_bot` column are switched to the equivalent `bot_type`
check, since the columns are slightly duplicative, and we can get away
with only checking bot_type.
This commit is contained in:
Alex Vandiver
2025-02-11 19:59:37 +00:00
committed by Tim Abbott
parent 44f0e936c2
commit f58c29b290
5 changed files with 40 additions and 4 deletions

View File

@@ -679,6 +679,31 @@ class UserPresenceTests(ZulipTestCase):
result_dict = self.assert_json_success(result)
self.assertEqual(set(result_dict["presences"].keys()), {othello.email})
def test_query_counts(self) -> None:
self.login("hamlet")
with self.assert_database_query_count(6):
# 1. session
# 2. narrow user cache
# 3. client
# 4. lock the userpresence row
# 5. update the userpresence row
# 6. select other userpresence data
self.assert_json_success(
self.client_post("/json/users/me/presence", {"status": "active"})
)
with self.assert_database_query_count(3, keep_cache_warm=True):
# With a warm cache, we skip the first three queries
self.assert_json_success(
self.client_post("/json/users/me/presence", {"status": "active"})
)
with self.assert_database_query_count(3, keep_cache_warm=True):
# It's the same story if we're becoming idle, as well
self.assert_json_success(
self.client_post("/json/users/me/presence", {"status": "idle"})
)
class SingleUserPresenceTests(ZulipTestCase):
def test_email_access(self) -> None: