ssb: Faster loads by encouraging the right queries with CTEs in fetch_about.
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				Build Tilde Friends / Build-All (push) Has been cancelled
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	Build Tilde Friends / Build-All (push) Has been cancelled
				
			This commit is contained in:
		@@ -1,5 +1,5 @@
 | 
			
		||||
{
 | 
			
		||||
	"type": "tildefriends-app",
 | 
			
		||||
	"emoji": "🦀",
 | 
			
		||||
	"previous": "&YeFLcHjD39FzsciGDfXuLd0hPzu4Rrp7QlMA7NaUCio=.sha256"
 | 
			
		||||
	"previous": "&RkHUl/WRe0UpvTB2W6cw0f4AeupL/2PEI1pXg5PDXBg=.sha256"
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -177,6 +177,7 @@ class TfElement extends LitElement {
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		const k_account_chunk_size = 4096;
 | 
			
		||||
		const k_chunk_size = 1024;
 | 
			
		||||
		let min_row_id = 0;
 | 
			
		||||
		console.log(
 | 
			
		||||
@@ -189,43 +190,49 @@ class TfElement extends LitElement {
 | 
			
		||||
		);
 | 
			
		||||
		try {
 | 
			
		||||
			while (true) {
 | 
			
		||||
				let max_seen;
 | 
			
		||||
				for (let account_chunk = 0; account_chunk < ids.length; account_chunk += k_account_chunk_size) {
 | 
			
		||||
					let ids_chunk = ids.slice(account_chunk, account_chunk + k_account_chunk_size);
 | 
			
		||||
					let abouts = await tfrpc.rpc.query(
 | 
			
		||||
						`
 | 
			
		||||
						SELECT * FROM (
 | 
			
		||||
							WITH
 | 
			
		||||
								past AS (
 | 
			
		||||
									SELECT
 | 
			
		||||
										messages.rowid AS rowid, messages.author, json(messages.content) AS content, messages.sequence
 | 
			
		||||
									FROM
 | 
			
		||||
								messages,
 | 
			
		||||
								json_each(?1) AS following
 | 
			
		||||
										messages
 | 
			
		||||
									WHERE
 | 
			
		||||
								messages.author = following.value AND
 | 
			
		||||
								messages.content ->> 'type' = 'about' AND
 | 
			
		||||
										messages.rowid > ?3 AND
 | 
			
		||||
								messages.rowid <= ?4
 | 
			
		||||
							UNION
 | 
			
		||||
										messages.rowid <= ?4 AND
 | 
			
		||||
										messages.content ->> 'type' = 'about'
 | 
			
		||||
								),
 | 
			
		||||
								current AS (
 | 
			
		||||
									SELECT
 | 
			
		||||
										messages.rowid AS rowid, messages.author, json(messages.content) AS content, messages.sequence
 | 
			
		||||
									FROM
 | 
			
		||||
								messages,
 | 
			
		||||
								json_each(?2) AS following
 | 
			
		||||
										messages
 | 
			
		||||
									WHERE
 | 
			
		||||
								messages.author = following.value AND
 | 
			
		||||
								messages.content ->> 'type' = 'about' AND
 | 
			
		||||
										messages.rowid > ?6 AND
 | 
			
		||||
								messages.rowid <= ?4
 | 
			
		||||
										messages.rowid <= ?4 AND
 | 
			
		||||
										messages.content ->> 'type' = 'about'
 | 
			
		||||
								)
 | 
			
		||||
								SELECT * FROM past
 | 
			
		||||
								JOIN json_each(?1) AS following
 | 
			
		||||
								ON past.author = following.value
 | 
			
		||||
								UNION SELECT * FROM current
 | 
			
		||||
								JOIN json_each(?2) AS following
 | 
			
		||||
								ON current.author = following.value
 | 
			
		||||
								ORDER BY rowid LIMIT ?5
 | 
			
		||||
						`,
 | 
			
		||||
						[
 | 
			
		||||
						JSON.stringify(ids.filter((id) => cache.about[id])),
 | 
			
		||||
						JSON.stringify(ids.filter((id) => !cache.about[id])),
 | 
			
		||||
							JSON.stringify(ids_chunk.filter((id) => cache.about[id])),
 | 
			
		||||
							JSON.stringify(ids_chunk.filter((id) => !cache.about[id])),
 | 
			
		||||
							cache.last_row_id,
 | 
			
		||||
							max_row_id,
 | 
			
		||||
							k_chunk_size,
 | 
			
		||||
							min_row_id,
 | 
			
		||||
						]
 | 
			
		||||
					);
 | 
			
		||||
				let max_seen;
 | 
			
		||||
					for (let about of abouts) {
 | 
			
		||||
						let content = JSON.parse(about.content);
 | 
			
		||||
						if (content.about === about.author) {
 | 
			
		||||
@@ -238,6 +245,8 @@ class TfElement extends LitElement {
 | 
			
		||||
						}
 | 
			
		||||
						max_seen = about.rowid;
 | 
			
		||||
					}
 | 
			
		||||
					console.log(account_chunk, '/', ids.length, 'accounts');
 | 
			
		||||
				}
 | 
			
		||||
				console.log(
 | 
			
		||||
					'cache =',
 | 
			
		||||
					cache.last_row_id,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user