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

continue tries to move to last place we had progress #13668

Merged
merged 3 commits into from
Mar 14, 2017
Merged

Conversation

Bjvanminnen
Copy link
Contributor

@Bjvanminnen Bjvanminnen commented Mar 8, 2017

When you click "continue" on the unit overview page, the current behavior is that it looks for the first lesson in the script that you haven't passed (ignoring things like unplugged, hidden, etc.).

This is problematic in that if you choose to have you class skip a stage, continue will still keep trying to take you back to it.

What we'd instead like to do is to find the last level that you made any progress on, and then take you to the next level after that (again ignoring things like unplugged, etc.)

def next_unpassed_progression_level(script)
user_levels_by_level = user_levels_by_level(script)

script.script_levels.detect do |script_level|
user_level = last_progressed_level(script)
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that we already did the DB query to get user_levels_by_level, is it possible to avoid the DB query for last_progressed_level? It may not be (may not make sense to), I just want to raise the question.

Copy link
Contributor

Choose a reason for hiding this comment

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

In particular, can the code be refactored to define next_unpassed. If it is non-nil, return it (without calling last_progressed_level). If it is nil, compute last_script_level (with or without the DB query).

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, never mind, next_unpassed uses script_level_index.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One option would be to do something like this:

user_level = user_levels_by_level.values.flatten.sort_by!(&:updated_at).last

which avoids another db query, at the expensive of some complexity. The number of user_levels here should be on the order of ~100 at most, so I don't think we need to worry too much about the cost of sorting.

Thoughts?

end

# Returns the next script_level for the next progression level in the given
# script that hasn't yet been passed, starting its search at the last level we submitted
Copy link
Contributor

Choose a reason for hiding this comment

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

How does (if at all) this work if we are writing progress asynchronously? Do we care?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe that historically we (a) only used async progress writing during HoC and (b) we chose not to use it during last HoC

In the case that we were to turn on async progress writing, this feature would not work as expected, but I don't think that is all that bad of a bad.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also used for migrations to the user_levels table.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Meaning that if we had a migration in progress, we might get unexpected results here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Meaning that if we turn on async writes (because of a migration or otherwise), we might get unexpected results here. Granted, I'm not sure we care...just raising the question.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess the other risk is that even once the migration is finished, last_modified might no longer represent the last level the user actually had progress on.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is less of a concern, I think, because the queue operates in a FIFO manner. So the ordering of the timestamps should at least be correct. Right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool. I think we care a little about getting unexpected results (because we're running a migration for example), but not a lot. I think the alternative would be to store this "last progress level" somewhere else, which would mean an extra write every time we made progress, which seems less palatable.

script_level_index = 0
if user_level
last_script_level = user_level.level.script_levels.where(script_id: script.id).first
script_level_index = script.script_levels.find_index(last_script_level) if last_script_level
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use last_script_level.chapter - 1 instead of doing a find_index here.

@Bjvanminnen Bjvanminnen merged commit eac0cca into staging Mar 14, 2017
@Bjvanminnen Bjvanminnen deleted the nextInScript branch March 14, 2017 00:33
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.

None yet

3 participants