Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I expect stale results after redirect on local environment?

After I post a new entity to the datastore, I redirect the page to a new URL that lists all of the entities in that group. When I redirect, the page shows stale results and I have to reload to see the new list of entities in the datastore.

I know about eventual consistency. Is that why I'm seeing the stale result?

For example,

my datastore my have one user - User 1 Then, in a form, I add a user - User 2 This entity is put to the datastore and then I redirect to a new url, i.e. 'get/users'

On the redirect I only see User 1, but if I refresh the page I see User 2. Any way I can guarantee or help to prevent the stale results?

like image 695
kevin Avatar asked Apr 02 '13 20:04

kevin


People also ask

Should I test redirect rules in the staging environment?

If you test your redirect rules in the staging environment of your old website, you only have to push them live for the migration, without worrying about changing the implementation from the staging site of the new website to the old domain.

How to test redirects before migrating your website?

Test your redirects on your staging website before the new website goes live in order to minimise the risk of going live with faulty redirects. Testing your redirects before the migration does not eliminate the need to test them after the migration. Collect all URLs that have clicks, impressions, sessions from organic search and backlinks.

How to avoid staleelementreferenceexception when using expected conditions?

Use ExpectedConditions.refreshed to avoid StaleElementReferenceException and retrieve the element again. This method updates the element by redrawing it and we can access the referenced element.

What is the difference between stale and referenced web elements?

Cause 1: The referenced web element has been deleted completely. Stale means old, decayed, no longer fresh. Stale Element means an old element or no longer available element.


1 Answers

Yes, this is caused by "eventual consistency" as you put it.

I have a few recommendations:

  1. Use AJAX. Using a redirect results in unnecessary extra work:
    • an extra (unnecessary) HTTP request (network bandwidth, latency, server resources, mobile data costs, etc.)
    • an extra (unnecessary) datastore query to confirm what you already know
  2. Use JavaScript to update the list of users displayed to the user on success of the XMLHttpRequest; don't perform another query.
  3. If you really need the user object, you can do a get by key (not a query) from the datastore and this will be strongly consistent.
  4. If you really want a strongly consistent query, use an ancestor query, which is strongly consistent. Send the results of that query back in the success response and update your UI accordingly.
    • Note: use of ancestor queries requires an entity group, which is limited to ~ 1 write/second; this rate would be sufficient for, say, recording comments on a blog post, but would likely be insufficient for creation of new users in your application
like image 78
bossylobster Avatar answered May 21 '23 00:05

bossylobster