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

⚡️ Improve page load by optimizing the caching code #492

Merged
merged 6 commits into from
Jan 26, 2024

Conversation

spencerjibz
Copy link
Collaborator

@spencerjibz spencerjibz commented Jan 22, 2024

What does this PR do?

It reduces the time it takes for the search results to appear on the search page by caching the next, current and previous page search results simultaneously using Redis pipelining and mini-mocha sync methods. And deferring the caching of the caching of the search results once all the search results have been aggregated from the upstream search engines in the search function in the src/server/routes/search.rs file under the codebase by using a non-blocking concurrent/parallel tokio::spawn thread.

Why is this change important?

Caching results simultaneously and using a separate non-blocking thread will significantly reduce the time it takes to load the search results to the user. Thus improving user experience and improving the search engine speed.

The idea is to cache results for the next, current and previous pages simultaneously, which can help reduce the time it takes to cache the results from the three pages. Also, caching the search results only when the search results from all three pages have been completely fetched and aggregated. Once the results are fetched and aggregated, this will spawn a new parallel and concurrent thread using something like tokio::spawn. The search results from all three pages would be passed to it and cached parallelly and concurrently using tokio::spawn.

How to test this PR locally?

It can be tested by installing and running Websurfx as mentioned in the docs and on the readme and by launching the browser and thoroughly testing.
Run the app with any of the cache_stores enabled via feature flags (redis-cache & hybrid ), and use a Redis-client (either cli or a GUI like redisInsight and others). If you inspect Redis, you find that on each search, two more search_results are stored. Also in the browser, the previous and next search results are loaded faster.

Author's checklist

  • Spawn separate tokio tasks to cache the results (src/server/routes/search).
  • Use redis-pipeline to set multiple fields concurrently.
  • Change the cacher trait and all cache implementations to support caching multiple values.
  • Bump up version to v1.9.4

Related issues

Closes #444

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Congrats on making your first Pull Request and thanks for taking the time to improve Websurfx! ❤️!
Say hello by joining the conversation in our Discord

@ddotthomas

This comment was marked as off-topic.

Copy link
Owner

@neon-mmd neon-mmd left a comment

Choose a reason for hiding this comment

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

Sorry for the late review
Thanks ❤️ for working on this PR. We really appreciate it 👍 Since everything looks good. We will merge this PR as soon as possible 🚀 🙂 .

@ddotthomas
Copy link
Contributor

The search also does appear to be 4-6 seconds quicker now with the changes when I tested it.

@neon-mmd
Copy link
Owner

The search also does appear to be 4-6 seconds quicker now with the changes when I tested it.

I also seem to have similar results on my side when I tested it. So it seems to be a great improvement overall. Also, thanks ❤️ again to spencerjibz for the cool work. 🙂

@spencerjibz

This comment was marked as off-topic.

@spencerjibz

This comment was marked as off-topic.

Copy link
Collaborator

@alamin655 alamin655 left a comment

Choose a reason for hiding this comment

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

Approved! Let's merge this in. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

⚡️ Improve page load by optimizing the caching code
4 participants