[PWA] 16. Clean IDB
16 Clean pwa
2023-09-14 08:59:19 时间
When we save items to IndexDB, we need to think about clean the items or keep those in a short list.
IndexController.prototype._onSocketMessage = function(data) { var messages = JSON.parse(data); this._dbPromise.then(function(db) { if (!db) return; var tx = db.transaction('wittrs', 'readwrite'); var store = tx.objectStore('wittrs'); messages.forEach(function(message) { store.put(message); }); // TODO: keep the newest 30 entries in 'wittrs', // but delete the rest. // // Hint: you can use .openCursor(null, 'prev') to // open a cursor that goes through an index/store // backwards. store.index('by-date').openCursor(null, 'prev') .then((cursor)=>{ return cursor.advance(30); // only 30 itmes are kept }).then(function deleteCursor(cursor){ if(!cursor){ return; }else{ cursor.delete(); return cursor.continue().then(deleteCursor); } }) }); this._postsView.addPosts(messages); };
相关文章
- 8月16日,直击金融痛点!详解核心业务架构下移与智能运维
- Pytest(16)随机执行测试用例pytest-random-order[通俗易懂]
- Redis为什么默认16个数据库
- PostgreSQL 16 三则 “新功能更新”
- c语言设计计算器-210404-基于单片机的计算器(16键)系统设计
- LeetCode-16-最接近的三数之和
- 写好简历的16个关键点
- react源码解析16.concurrent模式_2023-03-15
- Java 近期新闻:GlassFish 7.0、Payara 平台、Apache NetBeans 16
- 使用 PHP 把 16 进制的颜色代码转换成 RGB 数组
- 最大赢家!天翼云一举斩获16项可信云认证
- Linux 16进制转换——快速、简便的体验(linux16进制转换)
- 曝特斯拉上海研发中心即将完工 16万的Model 2/Q呼之欲出?
- 16核提升的MySQL性能,操作更流畅(16核mysql性能)
- Oracle 16数据库升级至10实现优化升级(oracle 16转10)
- NASA科学家在16吨的模拟月壤上进行实验 以寻找处理方法