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] Fix the filtered_programs_for_user call #4724

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ def programs_page(user):
filter = request.args.get('filter', default=None, type=str)
submitted = True if filter == 'submitted' else None

result = DATABASE.filtered_programs_for_user({"username": from_user or username},
result = DATABASE.filtered_programs_for_user(from_user or username,
level=level,
adventure=adventure,
submitted=submitted,
Expand Down Expand Up @@ -1756,7 +1756,7 @@ def reset_page():
@requires_login_redirect
def profile_page(user):
profile = DATABASE.user_by_username(user['username'])
programs = DATABASE.filtered_programs_for_user({"username": user['username'], "public": 1})
programs = DATABASE.filtered_programs_for_user(user['username'], public=True)
public_profile_settings = DATABASE.get_public_profile_settings(current_user()['username'])

classes = []
Expand Down Expand Up @@ -2371,7 +2371,8 @@ def public_user_page(username):
user_public_info = DATABASE.get_public_profile_settings(username)
page = request.args.get('page', default=None, type=str)
if user_public_info:
user_programs = DATABASE.filtered_programs_for_user({"username": user['username'], "public": 1},
user_programs = DATABASE.filtered_programs_for_user(username,
public=True,
limit=10,
pagination_token=page)
next_page_token = user_programs.next_page_token
Expand Down
9 changes: 6 additions & 3 deletions website/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,15 @@ def programs_for_user(self, username):
"""
return PROGRAMS.get_many({"username": username}, reverse=True)

def filtered_programs_for_user(self, program_query, level=None, adventure=None, submitted=None,
limit=None, pagination_token=None, public=None):
def filtered_programs_for_user(self, username, level=None, adventure=None, submitted=None, public=None,
limit=None, pagination_token=None):
ret = []

# FIXME: Query by index, the current behavior is slow for many programs
# (See https://github.com/hedyorg/hedy/issues/4121)
programs = dynamo.GetManyIterator(PROGRAMS, program_query,
programs = dynamo.GetManyIterator(PROGRAMS, {"username": username},
reverse=True, batch_size=limit, pagination_token=pagination_token)

for program in programs:
if level and program.get('level') != int(level):
continue
Expand All @@ -217,6 +218,8 @@ def filtered_programs_for_user(self, program_query, level=None, adventure=None,
if submitted is not None:
if program.get('submitted') != submitted:
continue
if public is not None and bool(program.get('public')) != public:
continue

ret.append(program)

Expand Down
3 changes: 2 additions & 1 deletion website/for_teachers.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,12 @@ def public_programs(self, user, class_id, username):
filter = request.args.get('filter', default=None, type=str)
submitted = True if filter == 'submitted' else None

result = self.db.filtered_programs_for_user({"username": from_user, "public": 1},
result = self.db.filtered_programs_for_user(from_user,
level=level,
adventure=adventure,
submitted=submitted,
pagination_token=page,
public=True,
limit=10)

programs = []
Expand Down
Loading