Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #16069: Add a "Newest First" tag for reviewable questions #16534

Merged
merged 31 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0366952
Add backend functions for sorting questions with the newest first
qinghaoyang Nov 13, 2022
412fca4
Merge remote-tracking branch 'upstream/develop' into sorting_questions
qinghaoyang Nov 13, 2022
5283c47
Fix lint errors
qinghaoyang Nov 13, 2022
45fc067
Completes the covereage test
qinghaoyang Nov 13, 2022
449dc4b
Merge remote-tracking branch 'upstream/develop' into sorting_questions
qinghaoyang Nov 29, 2022
748de42
Fix mypy errors
qinghaoyang Nov 29, 2022
9f470bb
Merge remote-tracking branch 'upstream/develop' into sorting_questions
qinghaoyang Dec 4, 2022
581281c
Change backend functions
qinghaoyang Dec 6, 2022
baa32ff
Change frontend functions
qinghaoyang Dec 6, 2022
8370912
Fix lint errors
qinghaoyang Dec 6, 2022
c33e9d3
Fix mypy errors
qinghaoyang Dec 6, 2022
304673a
Fix arguments error
qinghaoyang Dec 6, 2022
5734746
Merge remote-tracking branch 'upstream/develop' into sorting_questions
qinghaoyang Dec 22, 2022
75bc4d8
Merge remote-tracking branch 'upstream/develop' into sorting_questions
qinghaoyang Dec 29, 2022
6c2bfdd
Use positional args
qinghaoyang Dec 29, 2022
807fdc8
Use Date as the default choice
qinghaoyang Dec 29, 2022
e04ce60
Fix backend errors
qinghaoyang Dec 29, 2022
8cc15ce
Add a constant in constants.ts
qinghaoyang Dec 29, 2022
19371f4
Fetch a batch of items one time
qinghaoyang Dec 30, 2022
44c8d20
Merge remote-tracking branch 'upstream/develop' into sorting_questions
qinghaoyang Dec 30, 2022
0959288
Fix mypy errors
qinghaoyang Dec 30, 2022
b7848b1
Update frontend test
qinghaoyang Dec 30, 2022
91f889c
Fixed frontend bugs
qinghaoyang Dec 31, 2022
39de584
Set sort_key as a mandatory argument
qinghaoyang Jan 9, 2023
c3fc3b4
Merge remote-tracking branch 'upstream/develop' into sorting_questions
qinghaoyang Jan 9, 2023
3f3e83e
Update frontend tests
qinghaoyang Jan 9, 2023
766a329
Change the default sort key of reviewable translations to date
qinghaoyang Jan 10, 2023
8d9849a
Fix a bug about calculating offset
qinghaoyang Jan 10, 2023
4e80671
Fix mypy errors
qinghaoyang Jan 10, 2023
428f2ee
Add indexes
qinghaoyang Jan 10, 2023
a7cadb5
Merge remote-tracking branch 'upstream/develop' into sorting_questions
qinghaoyang Jan 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Completes the covereage test
  • Loading branch information
qinghaoyang committed Nov 13, 2022
commit 45fc06761d2384bc9546259b28fea7cc94d1208c
30 changes: 16 additions & 14 deletions core/storage/suggestion/gae_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,28 +642,30 @@ def get_in_review_question_suggestions_by_offset(
cls.suggestion_type == feconf.SUGGESTION_TYPE_ADD_QUESTION,
)).order(-cls.created_on)

results = []
sorted_results: List[GeneralSuggestionModel] = []

while len(results) < limit:
while len(sorted_results) < limit:
suggestion_model: GeneralSuggestionModel = (
suggestion_query.fetch(1, offset=offset))[0]
offset += 1
if suggestion_model.author_id != user_id:
results.append(suggestion_model)
sorted_results.append(suggestion_model)

next_offset = offset
return (
sorted_results,
offset
)

else:
suggestion_query = cls.get_all().filter(datastore_services.all_of(
cls.status == STATUS_IN_REVIEW,
cls.suggestion_type == feconf.SUGGESTION_TYPE_ADD_QUESTION,
cls.author_id != user_id
))
suggestion_query = cls.get_all().filter(datastore_services.all_of(
cls.status == STATUS_IN_REVIEW,
cls.suggestion_type == feconf.SUGGESTION_TYPE_ADD_QUESTION,
cls.author_id != user_id
))

results: Sequence[GeneralSuggestionModel] = (
suggestion_query.fetch(limit, offset=offset)
)
next_offset = offset + len(results)
results: Sequence[GeneralSuggestionModel] = (
suggestion_query.fetch(limit, offset=offset)
)
next_offset = offset + len(results)

return (
results,
Expand Down
34 changes: 15 additions & 19 deletions core/storage/suggestion/gae_models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ def test_get_in_review_translation_suggestions_by_offset_no_limit(
def test_get_in_review_question_suggestions_by_offset(self) -> None:
suggestion_1_id = 'skill1.thread1'
suggestion_2_id = 'skill1.thread2'
suggestion_3_id = 'skill2.thread3'
user_id = 'author1'
limit = 1
suggestion_models.GeneralSuggestionModel.create(
Expand All @@ -600,6 +601,13 @@ def test_get_in_review_question_suggestions_by_offset(self) -> None:
suggestion_models.STATUS_IN_REVIEW, 'author_4',
'reviewer_2', self.change_cmd, 'category1',
suggestion_2_id, self.question_language_code)
suggestion_models.GeneralSuggestionModel.create(
feconf.SUGGESTION_TYPE_ADD_QUESTION,
feconf.ENTITY_TYPE_SKILL,
'skill_1', self.target_version_at_submission,
suggestion_models.STATUS_IN_REVIEW, 'author1',
'reviewer_2', self.change_cmd, 'category1',
suggestion_3_id, self.question_language_code)

results, offset_1 = (
suggestion_models.GeneralSuggestionModel
Expand Down Expand Up @@ -636,31 +644,19 @@ def test_get_in_review_question_suggestions_by_offset(self) -> None:
self.assertEqual(len(results), 0)
self.assertEqual(offset_3, 2)

newest_results, offset_1 = (
sorted_results, offset_4 = (
suggestion_models.GeneralSuggestionModel
.get_in_review_question_suggestions_by_offset(
limit=limit,
limit=2,
offset=0,
user_id=user_id,
newest_first=True))
# Ruling out the possibility of None for mypy type checking.
assert newest_results is not None
self.assertEqual(len(newest_results), limit)
self.assertEqual(newest_results[0].id, suggestion_2_id)
self.assertEqual(offset_1, 1)

oldest_results, offset_2 = (
suggestion_models.GeneralSuggestionModel
.get_in_review_question_suggestions_by_offset(
limit=limit,
offset=offset_1,
user_id=user_id,
newest_first=True))
# Ruling out the possibility of None for mypy type checking.
assert oldest_results is not None
self.assertEqual(len(oldest_results), limit)
self.assertEqual(oldest_results[0].id, suggestion_1_id)
self.assertEqual(offset_2, 2)
assert sorted_results is not None
self.assertEqual(len(sorted_results), 2)
self.assertEqual(sorted_results[0].id, suggestion_2_id)
self.assertEqual(sorted_results[1].id, suggestion_1_id)
self.assertEqual(offset_4, 3)

def test_user_created_suggestions_by_offset(self) -> None:
authored_translation_suggestion_id = 'exploration.exp1.thread_6'
Expand Down