ssb: Prefer getting last message sequence from the messages_stats table if we don't need the message id.  Trying to chip away at things I see in profiles.
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build Tilde Friends / Build-All (push) Successful in 32m0s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build Tilde Friends / Build-All (push) Successful in 32m0s
				
			This commit is contained in:
		
							
								
								
									
										49
									
								
								src/ssb.db.c
									
									
									
									
									
								
							
							
						
						
									
										49
									
								
								src/ssb.db.c
									
									
									
									
									
								
							| @@ -981,27 +981,52 @@ bool tf_ssb_db_get_latest_message_by_author(tf_ssb_t* ssb, const char* author, i | ||||
| 	bool found = false; | ||||
| 	sqlite3_stmt* statement; | ||||
| 	sqlite3* db = tf_ssb_acquire_db_reader(ssb); | ||||
| 	const char* query = "SELECT id, sequence FROM messages WHERE author = ?1 ORDER BY sequence DESC LIMIT 1"; | ||||
| 	if (sqlite3_prepare(db, query, -1, &statement, NULL) == SQLITE_OK) | ||||
|  | ||||
| 	if (out_message_id) | ||||
| 	{ | ||||
| 		if (sqlite3_bind_text(statement, 1, author, -1, NULL) == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW) | ||||
| 		const char* query = "SELECT id, sequence FROM messages WHERE author = ?1 ORDER BY sequence DESC LIMIT 1"; | ||||
| 		if (sqlite3_prepare(db, query, -1, &statement, NULL) == SQLITE_OK) | ||||
| 		{ | ||||
| 			if (out_sequence) | ||||
| 			if (sqlite3_bind_text(statement, 1, author, -1, NULL) == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW) | ||||
| 			{ | ||||
| 				*out_sequence = sqlite3_column_int64(statement, 1); | ||||
| 				if (out_sequence) | ||||
| 				{ | ||||
| 					*out_sequence = sqlite3_column_int64(statement, 1); | ||||
| 				} | ||||
| 				if (out_message_id) | ||||
| 				{ | ||||
| 					strncpy(out_message_id, (const char*)sqlite3_column_text(statement, 0), out_message_id_size - 1); | ||||
| 				} | ||||
| 				found = true; | ||||
| 			} | ||||
| 			if (out_message_id) | ||||
| 			{ | ||||
| 				strncpy(out_message_id, (const char*)sqlite3_column_text(statement, 0), out_message_id_size - 1); | ||||
| 			} | ||||
| 			found = true; | ||||
| 			sqlite3_finalize(statement); | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			tf_printf("%s: prepare failed: %s\n", __FUNCTION__, sqlite3_errmsg(db)); | ||||
| 		} | ||||
| 		sqlite3_finalize(statement); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		tf_printf("%s: prepare failed: %s\n", __FUNCTION__, sqlite3_errmsg(db)); | ||||
| 		const char* query = "SELECT max_sequence FROM messages_stats WHERE author = ?1"; | ||||
| 		if (sqlite3_prepare(db, query, -1, &statement, NULL) == SQLITE_OK) | ||||
| 		{ | ||||
| 			if (sqlite3_bind_text(statement, 1, author, -1, NULL) == SQLITE_OK && sqlite3_step(statement) == SQLITE_ROW) | ||||
| 			{ | ||||
| 				if (out_sequence) | ||||
| 				{ | ||||
| 					*out_sequence = sqlite3_column_int64(statement, 0); | ||||
| 				} | ||||
| 				found = true; | ||||
| 			} | ||||
| 			sqlite3_finalize(statement); | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			tf_printf("%s: prepare failed: %s\n", __FUNCTION__, sqlite3_errmsg(db)); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	tf_ssb_release_db_reader(ssb, db); | ||||
| 	return found; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user