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

Make lookup flash stateless #119

Open
magical opened this issue Jul 13, 2018 · 1 comment
Open

Make lookup flash stateless #119

magical opened this issue Jul 13, 2018 · 1 comment

Comments

@magical
Copy link
Member

magical commented Jul 13, 2018

When lookup finds a close-but-not-exact match, it redirects to the thing it found and displays a flash message to let you know (for example, treeecko).

The flash is currently implemented by setting a variable containing the message in the user session, which sets a session cookie. The session is checked on every page load, and if there is a pending message, it is displayed. This is a fairly common way to implement flashes.

It would be nice to get rid of all our uses of the session (there aren't many) and make veekun completely stateless.

I propose changing lookup to pass this information through a query parameter instead of a session cookie. Specifically, if you lookup up "treeecko" and we find a single close match, the lookup would redirect to /dex/pokemon/treecko?from_lookup=treeecko. Every resource page would check for this parameter and, if present, plug its value into an appropriate flash message. We could even include a bit of javascript that uses history.replaceState() to hide the parameter after the page loads.

This parameter would also be helpful if we ever implement autocorrection of 404s. If someone navigates to /dex/pokemon/treeecko, it would be nice to automatically do a lookup and redirect them to /dex/pokemon/treecko. But i'm paranoid about accidentally causing redirect loops if we do that. We could use the from_lookup parameter to detect loops.

Related to #115

magical added a commit to veekun/spline that referenced this issue Jul 14, 2019
Indisciminately calling session.save() in flash.pop_messages() was
causing us to save the session on practically every page load,
regardless of whether there were any messages to display.

Somewhat related to veekun/spline-pokedex#119, which was causing a
similar problem.
@magical
Copy link
Member Author

magical commented Jul 15, 2019

I'm going to punt on this idea until after the pyramid port is done. Turn out sessions aren't really that annoying to hook up.

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

No branches or pull requests

1 participant