-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from redis/fix-unnecessary-commands-for-first…
…-search-#218 Performance improvement for first - avoids unnecessary pagination.
- Loading branch information
Showing
2 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ class Member(BaseHashModel): | |
last_name: str = Field(index=True) | ||
email: str = Field(index=True) | ||
join_date: datetime.date | ||
age: int = Field(index=True) | ||
age: int = Field(index=True, sortable=True) | ||
bio: str = Field(index=True, full_text_search=True) | ||
|
||
class Meta: | ||
|
@@ -357,6 +357,43 @@ def test_validation_passes(m): | |
) | ||
assert member.first_name == "Andrew" | ||
|
||
@pytest.mark.asyncio | ||
async def test_retrieve_first(m): | ||
member = m.Member( | ||
first_name="Simon", | ||
last_name="Prickett", | ||
email="[email protected]", | ||
join_date=today, | ||
age=99, | ||
bio="This is the bio field for this user.", | ||
) | ||
|
||
await member.save() | ||
|
||
member2 = m.Member( | ||
first_name="Another", | ||
last_name="Member", | ||
email="[email protected]", | ||
join_date=today, | ||
age=98, | ||
bio="This is the bio field for this user.", | ||
) | ||
|
||
await member2.save() | ||
|
||
member3 = m.Member( | ||
first_name="Third", | ||
last_name="Member", | ||
email="[email protected]", | ||
join_date=today, | ||
age=97, | ||
bio="This is the bio field for this user.", | ||
) | ||
|
||
await member3.save() | ||
|
||
first_one = await m.Member.find().sort_by("age").first() | ||
assert first_one == member3 | ||
|
||
@pytest.mark.asyncio | ||
async def test_saves_model_and_creates_pk(m): | ||
|