Search: Index Caching Issues
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
- Issue 类型
- 重构
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- javascript
- 领域
- search
调研方向
阅读 js/search.js,尤其是前四个函数,以及前两个在 localStorage 中加载和缓存语言索引的函数。将当前按语言缓存的行为与 issue 中描述的 Cache API、OPFS 或浏览器管理的缓存选项进行比较;完成工作的前提是就一种能够处理未使用索引的替代策略达成一致并加以实现。
由索引模型根据 Issue 内容生成。
描述
The way the search caches indexes is, in my opinion, not ideal.
Background
The current search feature caches the indexes in localStorage, using a unique key for each language.
Related code: https://github.com/php/web-php/blob/e7cfbe98203d93e00aac7c0d159d7c9c3d4faadd/js/search.js#L19 (the first 4 functions, but mostly the first 2, here deal with loading and caching the indexes)
The search indexes are ~2.1 MB (.json file size) and localStorage quota is (generally) 5MB according to https://developer.mozilla.org/en-US/docs/Web/API/Storage_API/Storage_quotas_and_eviction_criteria
The current search uses localStorage and caches the indexes with a key for each specific language.
This means that if a user uses the manual in multiple languages, they can store at most 2 before hitting the localStorage quota.
This doesn't stop search working in further languages - the indexes of further visited languages just don't get cached.
However, if a user visits a language, then never returns to it, the indexes for that language are never considered for deletion, and data in localStorage never expires otherwise (unless the user manually clears their data, or the browser decides to delete data from a site not recently visited - I don't know the specifics of browser behavior in this regard)
This means that if the user regularly uses php.net, that (old) unused data remains in localStorage forever, preventing the storage of further data. At the moment, based on a quick search of the web-php repo, this is just other search indexes, but could be used for other functionality in the future.
Alternative Options
I'm not very familiar with explicitly caching data client-side, but based on some (relatively quick) research I think that if this functionality is to be retained, it should be rewritten to use either Cache API or OPFS. These seem to be designed to do exactly what the search is using localStorage for, and the storage quotas are much larger.
An advantage of going with OPFS would be that it would be trivial to manage cached indexes for all languages (listing them in a directory) and deleting unused ones, if that's desirable.
The other alternative would be to get rid of JS caching altogether and just let the browser handle caching as with any other web request.
Does anyone else have thoughts on this?
- 主要语言
- PHP
- 星标
- 1.1k
- 派生
- 641
- 平均合并
- 1 天 11 小时
- 30 天内合并 PR
- 19
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
php/web-php 的其他 Issue
-
Bug Status: Needs Triage
难度 2/5 1-3 小时 新手友好度 75/100
-
Page: downloads
难度 3/5 1-2 天 新手友好度 55/100
-
Page: downloads
难度 3/5 1-2 天 新手友好度 62/100
-
Bug Status: Needs Triage
难度 3/5 1-2 天 新手友好度 55/100
相似的 Issue
-
tooling
难度 2/5 1-3 小时 新手友好度 75/100
-
UX
难度 2/5 1-3 小时 新手友好度 70/100
ProfessionalWiki/NeoWiki#1525 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 1/5 1 小时以内 新手友好度 90/100
OpenConext/OpenConext-engineblock#2122 ·
-
Bug
难度 2/5 1-3 小时 新手友好度 70/100
Automattic/safe-publish#594 ·