git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit 0df7b2e9903705c4b2201aa29a6a6c1560b102af

only cache old views for maximum of 30 minutes (instead of until restart)

Matt McKegg committed on 11/10/2016, 9:54:27 AM
Parent: 402f85029889d7cc332cef170ab52fdc69bf4ae4

Files changed

main-window.jschanged
main-window.jsView
@@ -42,8 +42,19 @@
4242 [ssbClient.id]: screenView(ssbClient.id),
4343 '/notifications': screenView('/notifications')
4444 })
4545
46+ var lastViewed = {}
47+
48+ // delete cached view after 30 mins of last seeing
49+ setInterval(() => {
50+ views.keys().forEach((view) => {
51+ if (lastViewed[view] !== true && Date.now() - lastViewed[view] > (30 * 60e3) && view !== currentView()) {
52+ views.delete(view)
53+ }
54+ })
55+ }, 60e3)
56+
4657 var canGoForward = Value(false)
4758 var canGoBack = Value(false)
4859 var currentView = Value('/public')
4960
@@ -95,8 +106,9 @@
95106 // scoped
96107
97108 function tab (name, view) {
98109 var instance = views.get(view)
110+ lastViewed[view] = true
99111 return h('a', {
100112 'ev-click': function (ev) {
101113 if (instance.pendingUpdates && instance.pendingUpdates() && instance.reload) {
102114 instance.reload()
@@ -135,8 +147,17 @@
135147 function setView (view) {
136148 if (!views.has(view)) {
137149 views.put(view, screenView(view))
138150 }
151+
152+ if (lastViewed[view] !== true) {
153+ lastViewed[view] = Date.now()
154+ }
155+
156+ if (currentView() && lastViewed[currentView()] !== true) {
157+ lastViewed[currentView()] = Date.now()
158+ }
159+
139160 if (view !== currentView()) {
140161 canGoForward.set(false)
141162 canGoBack.set(true)
142163 forwardHistory.length = 0

Built with git-ssb-web