Refactor: Async backend + SQLite caching (Performance & Persistence)#9
Open
xkilldash9x wants to merge 3 commits intoNilchSearch:mainfrom
Open
Refactor: Async backend + SQLite caching (Performance & Persistence)#9xkilldash9x wants to merge 3 commits intoNilchSearch:mainfrom
xkilldash9x wants to merge 3 commits intoNilchSearch:mainfrom
Conversation
…backend Major overhaul to address critical privacy and integrity violations caused by the use of a public CORS proxy. Backend Changes (main.py): * Implemented `flask-cors` to whitelist frontend origins, allowing the frontend to communicate directly with the API. * Refactored the entire application into a class-based architecture (`BraveClient`, `SearchCache`, `InfoboxResolver`) for better maintainability and testing. * Added comprehensive type hints and `TypedDict` definitions. * Patched a potential RCE vulnerability in the calculator logic by restricting the `eval()` execution scope. Frontend Changes (images, results, videos): * Removed all references to `api.codetabs.com`. Requests now fetch directly from the backend API. * Switched to `URLSearchParams` for pagination to fix a bug where page parameters were infinitely appended to the URL. * Added proper error handling for network response failures.
whitelists from env var
modified: frontend/default.html new file: frontend/flask_app.py modified: frontend/images.html modified: frontend/index.html modified: frontend/results.html modified: frontend/videos.html
Contributor
Author
|
oh this pr has the fix for cors that turned out to not be the fix, also I havent had ANY time to do testing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've been messing around with the
nilchbackend and put together a refactor to solve a couple of stability things I noticed.Right now, since the cache is just a Python list,
nilchforgets all the search results every time the server restarts (which happens a lot on standard WSGI hosts). This kills the hit rate and wastes API quota. I also moved the route handlers toasyncso the server doesn't lock up while waiting on Brave or Wikipedia to reply.Changes
1. Persistent Caching (SQLite)
listcache for a localsearch_cache.db(SQLite).nilchcrashes or redeploys, the cache is still there.2. Async I/O
/api/search,/api/images) toasync def.3. Image Search Caching
/api/imagesendpoint.4. Frontend Tweaks
results.htmlandimages.html./api/...) so the code works in both dev and prod without changing lines.