Thanks to visit codestin.com
Credit goes to github.com

Skip to content

LCORE-1249: benchmarks for listing conversation for one user#1121

Merged
tisnik merged 1 commit into
lightspeed-core:mainfrom
tisnik:lcore-1249-benchmarks-for-listing-conversation-for-one-user
Feb 9, 2026
Merged

LCORE-1249: benchmarks for listing conversation for one user#1121
tisnik merged 1 commit into
lightspeed-core:mainfrom
tisnik:lcore-1249-benchmarks-for-listing-conversation-for-one-user

Conversation

@tisnik

@tisnik tisnik commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

Description

LCORE-1249: benchmarks for listing conversation for one user

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement
  • Benchmarks improvement

Tools used to create PR

  • Assisted-by: N/A
  • Generated by: N/A

Related Tickets & Documents

  • Related Issue #LCORE-1249

Summary by CodeRabbit

Release Notes

  • Tests

    • Added comprehensive benchmarking and test suite for querying conversations filtered by individual users, covering empty, small, medium, and large database scenarios.
  • Chores

    • Enhanced conversation storage helpers with optional user ID parameters to support improved test data isolation and management.

@coderabbitai

coderabbitai Bot commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Added an optional user_id parameter to store_new_user_conversation() function and introduced a new list_conversation_for_one_user() helper. Added benchmark and test scaffolding across four database sizes to measure performance of querying conversations filtered by a specific user.

Changes

Cohort / File(s) Summary
Test and Benchmark Enhancements
tests/benchmarks/test_app_database.py
Extended store_new_user_conversation() with optional user_id parameter. Added list_conversation_for_one_user() helper function to query conversations by user. Introduced benchmark_list_conversations_for_one_user() and four test functions (test_list_conversations_for_one_user_empty_db, test_list_conversations_for_one_user_small_db, test_list_conversations_for_one_user_middle_db, test_list_conversations_for_one_user_large_db) to benchmark per-user listing across varying database sizes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and specifically describes the main change: adding benchmarks for listing conversations for a single user, which matches the core objective and changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@tests/benchmarks/test_app_database.py`:
- Around line 612-618: The benchmark computes user_id using float division which
yields strings like "50.0" that never match stored IDs; change the computation
of user_id to use integer division (records_to_insert // 2) or otherwise cast to
int so user_id becomes str(int) and matches the IDs created by
store_new_user_conversation; this will ensure list_conversation_for_one_user is
benchmarked with an existing user.
🧹 Nitpick comments (2)
tests/benchmarks/test_app_database.py (2)

306-323: Docstring doesn't match behavior and is missing the user_id parameter.

The docstring says "retrieval of one user conversation" but the function retrieves all conversations for one user (potentially multiple rows). Also, the user_id parameter is absent from the Parameters section.

📝 Suggested docstring fix
 def list_conversation_for_one_user(session: Session, user_id: str) -> None:
-    """Query and assert retrieval of one user conversation.
+    """Query and assert retrieval of conversations for one user.
 
-    This helper queries all UserConversation records and asserts that the
+    This helper queries UserConversation records for a given user and asserts that the
     result is a list (possibly empty). It is intended for use in a benchmark
     that measures the listing performance.
 
     Parameters:
         session (Session): SQLAlchemy session used to query conversations.
+        user_id (str): The user ID to filter conversations by.
 
     Returns:
         None
     """

595-609: Copy-paste docstring: says "listing all conversations" instead of "for one user".

📝 Suggested fix
-    """Prepare DB and benchmark listing all conversations.
+    """Prepare DB and benchmark listing conversations for one user.
 
-    Pre-populates the DB with ``records_to_insert`` entries and benchmarks
-    the performance of querying and retrieving all UserConversation rows.
+    Pre-populates the DB with ``records_to_insert`` entries and benchmarks
+    the performance of querying UserConversation rows for a single user.

Comment on lines +612 to +618
for id in range(records_to_insert):
# use explicit conversation ID and also user ID
store_new_user_conversation(session, str(id), str(id))
# user ID somewhere in the middle of database
user_id = str(records_to_insert / 2)
# then perform the benchmark
benchmark(list_conversation_for_one_user, session, user_id)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Bug: float division produces a user_id that never matches any stored record.

records_to_insert / 2 uses true division, yielding a float (e.g. 50.0). str(50.0) is "50.0", but stored user IDs are str(int) values like "50". The benchmark will therefore always query for a non-existent user and measure an empty-result path, defeating the purpose of the benchmark.

Use integer division (//) instead.

🐛 Proposed fix
-        user_id = str(records_to_insert / 2)
+        user_id = str(records_to_insert // 2)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for id in range(records_to_insert):
# use explicit conversation ID and also user ID
store_new_user_conversation(session, str(id), str(id))
# user ID somewhere in the middle of database
user_id = str(records_to_insert / 2)
# then perform the benchmark
benchmark(list_conversation_for_one_user, session, user_id)
for id in range(records_to_insert):
# use explicit conversation ID and also user ID
store_new_user_conversation(session, str(id), str(id))
# user ID somewhere in the middle of database
user_id = str(records_to_insert // 2)
# then perform the benchmark
benchmark(list_conversation_for_one_user, session, user_id)
🤖 Prompt for AI Agents
In `@tests/benchmarks/test_app_database.py` around lines 612 - 618, The benchmark
computes user_id using float division which yields strings like "50.0" that
never match stored IDs; change the computation of user_id to use integer
division (records_to_insert // 2) or otherwise cast to int so user_id becomes
str(int) and matches the IDs created by store_new_user_conversation; this will
ensure list_conversation_for_one_user is benchmarked with an existing user.

@tisnik tisnik merged commit dca93b5 into lightspeed-core:main Feb 9, 2026
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant