ssb: Now add back the about cache, and load times are getting good.
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build Tilde Friends / Build-All (push) Successful in 31m43s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build Tilde Friends / Build-All (push) Successful in 31m43s
				
			This commit is contained in:
		| @@ -1,5 +1,5 @@ | ||||
| { | ||||
| 	"type": "tildefriends-app", | ||||
| 	"emoji": "🦀", | ||||
| 	"previous": "&NajVQD/6DKISEDlnyAVYh3NPO/vxMN7ksNZy3FwI378=.sha256" | ||||
| 	"previous": "&VQsPosjAfr008a6UMb8vKmKxE/WS4DRKEspJL8Lewjw=.sha256" | ||||
| } | ||||
|   | ||||
| @@ -152,7 +152,32 @@ class TfElement extends LitElement { | ||||
|  | ||||
| 	async fetch_about(following, users) { | ||||
| 		let ids = Object.keys(following).sort(); | ||||
| 		console.log('loading about for', ids.length, 'accounts'); | ||||
| 		const k_cache_version = 2; | ||||
| 		let cache = await tfrpc.rpc.databaseGet('about'); | ||||
| 		let original_cache = cache; | ||||
| 		cache = cache ? JSON.parse(cache) : {}; | ||||
| 		if (cache.version !== k_cache_version) { | ||||
| 			cache = { | ||||
| 				version: k_cache_version, | ||||
| 				about: {}, | ||||
| 			}; | ||||
| 		} | ||||
|  | ||||
| 		for (let id of Object.keys(cache.about)) { | ||||
| 			if (ids.indexOf(id) == -1) { | ||||
| 				delete cache.about[id]; | ||||
| 			} else { | ||||
| 				users[id] = Object.assign( | ||||
| 					users[id] || {}, | ||||
| 					cache.about[id] | ||||
| 				); | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		let ids_out_of_date = ids.filter(x => cache.about[x]?.seq === undefined || (users[x]?.seq && users[x]?.seq > cache.about[x].seq)); | ||||
|  | ||||
| 		console.log('loading about for', ids.length, 'accounts', ids_out_of_date.length, 'out of date'); | ||||
| 		if (ids_out_of_date.length) { | ||||
| 			try { | ||||
| 				let rows = await tfrpc.rpc.query( | ||||
| 					` | ||||
| @@ -172,7 +197,7 @@ class TfElement extends LitElement { | ||||
| 						WHERE rank = 1 | ||||
| 						GROUP BY all_abouts.author | ||||
| 					`, | ||||
| 				[JSON.stringify(ids)] | ||||
| 					[JSON.stringify(ids_out_of_date)] | ||||
| 				); | ||||
| 				users = users || {}; | ||||
| 				for (let row of rows) { | ||||
| @@ -180,11 +205,30 @@ class TfElement extends LitElement { | ||||
| 						users[row.author] || {}, | ||||
| 						JSON.parse(row.about) | ||||
| 					); | ||||
| 					cache.about[row.author] = Object.assign( | ||||
| 						{seq: users[row.author].seq}, | ||||
| 						JSON.parse(row.about) | ||||
| 					); | ||||
| 				} | ||||
| 			console.log('updated users'); | ||||
| 			} catch (e) { | ||||
| 				console.log(e); | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		for (let id of ids_out_of_date) { | ||||
| 			if (!cache.about[id]?.seq) { | ||||
| 				cache.about[id] = {seq: users[id]?.seq ?? 0}; | ||||
| 			} | ||||
| 		}; | ||||
|  | ||||
| 		let new_cache = JSON.stringify(cache); | ||||
| 		if (new_cache != original_cache) { | ||||
| 			let start_time = new Date(); | ||||
| 			tfrpc.rpc.databaseSet('about', new_cache).then(function() { | ||||
| 				console.log('saving about took', (new Date() - start_time) / 1000); | ||||
| 			}); | ||||
| 		} | ||||
|  | ||||
| 		return Object.assign({}, users); | ||||
| 	} | ||||
|  | ||||
| @@ -365,7 +409,7 @@ class TfElement extends LitElement { | ||||
| 		for (let row of info) { | ||||
| 			users[row.author] = Object.assign( | ||||
| 				{ | ||||
| 					seq: row.max_seq, | ||||
| 					seq: row.max_sequence, | ||||
| 					ts: row.max_ts, | ||||
| 				}, | ||||
| 				users[row.author] | ||||
|   | ||||
		Reference in New Issue
	
	Block a user