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

cache edit pages for librarians when on view page #9166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RayBB
Copy link
Collaborator

@RayBB RayBB commented Apr 27, 2024

With this PR we will prefetch (cache) the edit page of authors/works/editions so when you click the edit button it should load nearly instantly.

Contributes to #9121

How it works:

  • Visit an author page
  • In the background, the edit page is automatically loaded (on page load and then on subsequent page focuses)
  • When you click the edit button it should load instantly from the cache.

Technical

  • We can't just load on focus because the focus event doesn't trigger if you just click a link normally

Testing

Side by side comparison of prod (no precache) vs testing (with precache). Button turns red when clicked.
Can you tell which is which?

trimmed_red_timer.mp4
Longer video showing not whole process
https://github.com/internetarchive/openlibrary/assets/921217/3a9125a6-ba6d-49fe-a2ea-50642e67d727

Script used to click two buttons at once:

function executeAtTopOfMinute() {
  const now = new Date();
  // Calculate the time difference to the top of the minute
  const targetTime = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes()+1, 0);
  const timeDifference = targetTime - now;
  // Execute the action after the calculated time difference
  setTimeout(() => {
                // turn button red and then click it
                document.querySelector('.editButton a').style = "background-color:red" 
		document.querySelector('.editButton a').click();
  }, timeDifference);
}

// Call the function to schedule the action
executeAtTopOfMinute();

Screenshot

No UI changes.

Stakeholders

@RayBB RayBB changed the base branch from master to cache-first-covers April 27, 2024 18:25
@RayBB RayBB force-pushed the cache-edit-pages branch 2 times, most recently from 3a9db74 to b62904a Compare May 6, 2024 22:56
Base automatically changed from cache-first-covers to master May 8, 2024 12:42
@RayBB RayBB changed the title cache edit pages cache edit pages for librarians when on view page May 8, 2024
@@ -5,7 +5,7 @@
<div id="editHistory">
<a class="linkButton larger" href="$page.key?m=history" title="$_('View the editing history of this page')">$_("History")</a>
</div>
<div class="editButton">
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This editButton class is on the "Cancel" button.
It has almost no effect, (other than a light aligning) and complicates detecting when to fetch the edit button.
So I just removed it.

@RayBB RayBB marked this pull request as ready for review May 8, 2024 14:45
@RayBB RayBB added the Needs: Review This issue/PR needs to be reviewed in order to be closed or merged (see comments). [managed] label May 8, 2024
@RayBB RayBB requested a review from cdrini May 8, 2024 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Review This issue/PR needs to be reviewed in order to be closed or merged (see comments). [managed]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants