chore: add twt_mentions table
This commit is contained in:
		
							parent
							
								
									fc762f3bf3
								
							
						
					
					
						commit
						aedc9245e5
					
				
							
								
								
									
										17
									
								
								feed.go
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								feed.go
									
									
									
									
									
								
							@ -605,14 +605,25 @@ func chunk(args []any, qry func(int) (string, int), maxArgs int) iter.Seq2[strin
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func refreshLastTwt(ctx context.Context, db db) error {
 | 
					func refreshLastTwt(ctx context.Context, db db) error {
 | 
				
			||||||
	_, err := db.ExecContext(ctx, `
 | 
						qry := `
 | 
				
			||||||
 | 
						delete from last_twt_on;
 | 
				
			||||||
	insert into last_twt_on
 | 
						insert into last_twt_on
 | 
				
			||||||
		select
 | 
							select
 | 
				
			||||||
			feed_id,
 | 
								feed_id,
 | 
				
			||||||
			max(strftime('%Y-%m-%dT%H:%M:%fZ', (substring(text, 1, instr(text, '	')-1)))) last_twt_on
 | 
								max(strftime('%Y-%m-%dT%H:%M:%fZ', (substring(text, 1, instr(text, '	')-1)))) last_twt_on
 | 
				
			||||||
		from twts
 | 
							from twts
 | 
				
			||||||
		group by feed_id
 | 
							group by feed_id
 | 
				
			||||||
	on conflict do update set last_twt_on = excluded.last_twt_on;
 | 
						on conflict(feed_id) do update set last_twt_on = excluded.last_twt_on;
 | 
				
			||||||
`)
 | 
						delete from twt_mentions;
 | 
				
			||||||
 | 
						insert into twt_mentions select ulid, unhex(replace(trim(value,'{}'),'-','')) feed_id from twts, json_each(mentions);
 | 
				
			||||||
 | 
						`
 | 
				
			||||||
 | 
						var err error
 | 
				
			||||||
 | 
						for _, stmt := range strings.Split(qry, ";") {
 | 
				
			||||||
 | 
							_, err = db.ExecContext(ctx, stmt)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return err
 | 
						return err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										8
									
								
								init.sql
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								init.sql
									
									
									
									
									
								
							@ -31,3 +31,11 @@ create table if not exists last_twt_on(
 | 
				
			|||||||
); 
 | 
					); 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CREATE INDEX if not exists twt_time on twts (ulid asc);
 | 
					CREATE INDEX if not exists twt_time on twts (ulid asc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					create table if not exists twt_mentions(
 | 
				
			||||||
 | 
						feed_id blob,
 | 
				
			||||||
 | 
						ulid blob,
 | 
				
			||||||
 | 
						primary key (feed_id)
 | 
				
			||||||
 | 
					); 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE INDEX if not exists twt_mention on twt_mentions (ulid asc);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user