chore: fixes
This commit is contained in:
		
							parent
							
								
									aedc9245e5
								
							
						
					
					
						commit
						69755e14d2
					
				
							
								
								
									
										14
									
								
								feed.go
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								feed.go
									
									
									
									
									
								
							@ -432,7 +432,7 @@ func storeRegistry(ctx context.Context, db db, in io.Reader) error {
 | 
				
			|||||||
		)
 | 
							)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if len(args) >= 16*1022 {
 | 
							if len(args) >= 16*1022 {
 | 
				
			||||||
			i+=len(args)
 | 
								i += len(args)
 | 
				
			||||||
			fmt.Println("store", i/7, i)
 | 
								fmt.Println("store", i/7, i)
 | 
				
			||||||
			tx, err := db.BeginTx(ctx, nil)
 | 
								tx, err := db.BeginTx(ctx, nil)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
@ -563,7 +563,7 @@ func (n TwtTime) Value() (driver.Value, error) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func makeULID(twt types.Twt) ulid.ULID {
 | 
					func makeULID(twt types.Twt) ulid.ULID {
 | 
				
			||||||
	text := fmt.Appendf(nil, "%s\t%+l", cmp.Or(twt.Twter().HashingURI, twt.Twter().URI), twt)
 | 
						text := fmt.Appendf(nil, "%s\t%+l", twt.Twter().URI, twt)
 | 
				
			||||||
	u := ulid.ULID{}
 | 
						u := ulid.ULID{}
 | 
				
			||||||
	u.SetTime(ulid.Timestamp(twt.Created()))
 | 
						u.SetTime(ulid.Timestamp(twt.Created()))
 | 
				
			||||||
	u.SetEntropy(sha3.SumSHAKE128(text, 10))
 | 
						u.SetEntropy(sha3.SumSHAKE128(text, 10))
 | 
				
			||||||
@ -608,14 +608,18 @@ func refreshLastTwt(ctx context.Context, db db) error {
 | 
				
			|||||||
	qry := `
 | 
						qry := `
 | 
				
			||||||
	delete from last_twt_on;
 | 
						delete from last_twt_on;
 | 
				
			||||||
	insert into last_twt_on
 | 
						insert into last_twt_on
 | 
				
			||||||
		select
 | 
							select distinct
 | 
				
			||||||
			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(feed_id) do update set last_twt_on = excluded.last_twt_on;
 | 
						on conflict(feed_id);
 | 
				
			||||||
	delete from twt_mentions;
 | 
						delete from twt_mentions;
 | 
				
			||||||
	insert into twt_mentions select ulid, unhex(replace(trim(value,'{}'),'-','')) feed_id from twts, json_each(mentions);
 | 
						insert into twt_mentions
 | 
				
			||||||
 | 
							select distinct
 | 
				
			||||||
 | 
								ulid,
 | 
				
			||||||
 | 
								unhex(replace(trim(value,'{}'),'-','')) feed_id
 | 
				
			||||||
 | 
							from twts, json_each(mentions);
 | 
				
			||||||
	`
 | 
						`
 | 
				
			||||||
	var err error
 | 
						var err error
 | 
				
			||||||
	for _, stmt := range strings.Split(qry, ";") {
 | 
						for _, stmt := range strings.Split(qry, ";") {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										35
									
								
								http.go
									
									
									
									
									
								
							
							
						
						
									
										35
									
								
								http.go
									
									
									
									
									
								
							@ -25,21 +25,19 @@ const hostname = "https://watcher.sour.is"
 | 
				
			|||||||
var PREAMBLE_DOCS = func() lextwt.Comments {
 | 
					var PREAMBLE_DOCS = func() lextwt.Comments {
 | 
				
			||||||
	c := add(nil, iAmTheWatcher)
 | 
						c := add(nil, iAmTheWatcher)
 | 
				
			||||||
	c = add(c, "")
 | 
						c = add(c, "")
 | 
				
			||||||
	c = add(c,"Usage:")
 | 
						c = add(c, "Usage:")
 | 
				
			||||||
	c = add(c,"    %s/api/plain/users              View list of users and latest twt date.", hostname)
 | 
						c = add(c, "    %s/api/plain/users              View list of users and latest twt date.", hostname)
 | 
				
			||||||
	c = add(c,"    %s/api/plain/twt                View all twts in decending order.", hostname)
 | 
						c = add(c, "    %s/api/plain/twt                View all twts in decending order.", hostname)
 | 
				
			||||||
	c = add(c,"    %s/api/plain/mentions?uri=:uri  View all mentions for uri in decending order.", hostname)
 | 
						c = add(c, "    %s/api/plain/mentions?uri=:uri  View all mentions for uri in decending order.", hostname)
 | 
				
			||||||
	c = add(c,"    %s/api/plain/conv/:hash         View all twts for a conversation subject.", hostname)
 | 
						c = add(c, "    %s/api/plain/conv/:hash         View all twts for a conversation subject.", hostname)
 | 
				
			||||||
	c = add(c,"")
 | 
						c = add(c, "")
 | 
				
			||||||
	c = add(c,"Options:")
 | 
						c = add(c, "Options:")
 | 
				
			||||||
	c = add(c,"    uri     Filter to show a specific users twts.")
 | 
						c = add(c, "    uri     Filter to show a specific users twts.")
 | 
				
			||||||
	c = add(c,"    offset  Start index for quey.")
 | 
						c = add(c, "    offset  Start index for quey.")
 | 
				
			||||||
	c = add(c,"    limit   Count of items to return (going back in time).")
 | 
						c = add(c, "    limit   Count of items to return (going back in time).")
 | 
				
			||||||
	return add(c,"")
 | 
						return add(c, "")
 | 
				
			||||||
}()
 | 
					}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func httpServer(ctx context.Context, app *appState) error {
 | 
					func httpServer(ctx context.Context, app *appState) error {
 | 
				
			||||||
	ctx, span := otel.Span(ctx)
 | 
						ctx, span := otel.Span(ctx)
 | 
				
			||||||
	defer span.End()
 | 
						defer span.End()
 | 
				
			||||||
@ -139,7 +137,7 @@ func httpServer(ctx context.Context, app *appState) error {
 | 
				
			|||||||
		w.Header().Set("Content-Type", "text/plain; charset=utf-8")
 | 
							w.Header().Set("Content-Type", "text/plain; charset=utf-8")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		uri := r.URL.Query().Get("uri")
 | 
							uri := r.URL.Query().Get("uri")
 | 
				
			||||||
		if uri == ""{
 | 
							if uri == "" {
 | 
				
			||||||
			reg := lextwt.NewTwtRegistry(PREAMBLE_DOCS, nil)
 | 
								reg := lextwt.NewTwtRegistry(PREAMBLE_DOCS, nil)
 | 
				
			||||||
			reg.WriteTo(w)
 | 
								reg.WriteTo(w)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -150,7 +148,6 @@ func httpServer(ctx context.Context, app *appState) error {
 | 
				
			|||||||
		args := make([]any, 0, 3)
 | 
							args := make([]any, 0, 3)
 | 
				
			||||||
		args = append(args, mention)
 | 
							args = append(args, mention)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
		limit := 100
 | 
							limit := 100
 | 
				
			||||||
		if v, ok := strconv.Atoi(r.URL.Query().Get("limit")); ok == nil {
 | 
							if v, ok := strconv.Atoi(r.URL.Query().Get("limit")); ok == nil {
 | 
				
			||||||
			limit = v
 | 
								limit = v
 | 
				
			||||||
@ -200,7 +197,6 @@ func httpServer(ctx context.Context, app *appState) error {
 | 
				
			|||||||
		`
 | 
							`
 | 
				
			||||||
		fmt.Println(qry, args)
 | 
							fmt.Println(qry, args)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
		rows, err := db.QueryContext(
 | 
							rows, err := db.QueryContext(
 | 
				
			||||||
			ctx, qry, args...,
 | 
								ctx, qry, args...,
 | 
				
			||||||
		)
 | 
							)
 | 
				
			||||||
@ -249,7 +245,6 @@ func httpServer(ctx context.Context, app *appState) error {
 | 
				
			|||||||
		reg.WriteTo(w)
 | 
							reg.WriteTo(w)
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
	http.HandleFunc("/api/plain/twt", func(w http.ResponseWriter, r *http.Request) {
 | 
						http.HandleFunc("/api/plain/twt", func(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
		ctx, span := otel.Span(r.Context())
 | 
							ctx, span := otel.Span(r.Context())
 | 
				
			||||||
		defer span.End()
 | 
							defer span.End()
 | 
				
			||||||
@ -266,7 +261,7 @@ func httpServer(ctx context.Context, app *appState) error {
 | 
				
			|||||||
			offset = v
 | 
								offset = v
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		twts, end, err := func(uri string, limit int, offset int64, ) ([]types.Twt, int64, error) {
 | 
							twts, end, err := func(uri string, limit int, offset int64) ([]types.Twt, int64, error) {
 | 
				
			||||||
			args := make([]any, 0, 3)
 | 
								args := make([]any, 0, 3)
 | 
				
			||||||
			where := `where feed_id in (select feed_id from feeds where state != 'permanantly-dead')`
 | 
								where := `where feed_id in (select feed_id from feeds where state != 'permanantly-dead')`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -311,7 +306,7 @@ func httpServer(ctx context.Context, app *appState) error {
 | 
				
			|||||||
				) using (feed_id)
 | 
									) using (feed_id)
 | 
				
			||||||
				where rowid in (
 | 
									where rowid in (
 | 
				
			||||||
					select rowid from twts
 | 
										select rowid from twts
 | 
				
			||||||
					` + where +`
 | 
										` + where + `
 | 
				
			||||||
					order by ulid asc
 | 
										order by ulid asc
 | 
				
			||||||
					limit ?
 | 
										limit ?
 | 
				
			||||||
					offset ?
 | 
										offset ?
 | 
				
			||||||
@ -351,7 +346,7 @@ func httpServer(ctx context.Context, app *appState) error {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			return twts, end, err
 | 
								return twts, end, err
 | 
				
			||||||
		} (uri, limit, offset)
 | 
							}(uri, limit, offset)
 | 
				
			||||||
		span.RecordError(err)
 | 
							span.RecordError(err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		preamble := add(PREAMBLE_DOCS, "twt range = 1  %d", end)
 | 
							preamble := add(PREAMBLE_DOCS, "twt range = 1  %d", end)
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								init.sql
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								init.sql
									
									
									
									
									
								
							@ -35,7 +35,7 @@ CREATE INDEX if not exists twt_time on twts (ulid asc);
 | 
				
			|||||||
create table if not exists twt_mentions(
 | 
					create table if not exists twt_mentions(
 | 
				
			||||||
	feed_id blob,
 | 
						feed_id blob,
 | 
				
			||||||
	ulid blob,
 | 
						ulid blob,
 | 
				
			||||||
	primary key (feed_id)
 | 
						primary key (feed_id, ulid)
 | 
				
			||||||
); 
 | 
					); 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CREATE INDEX if not exists twt_mention on twt_mentions (ulid asc);
 | 
					CREATE INDEX if not exists twt_mention on twt_mentions (ulid asc);
 | 
				
			||||||
 | 
				
			|||||||
@ -228,7 +228,7 @@ func newTraceProvider(ctx context.Context, name string) (func(context.Context) e
 | 
				
			|||||||
		}, nil
 | 
							}, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return func(ctx context.Context) error {return nil}, nil
 | 
						return func(ctx context.Context) error { return nil }, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func newMeterProvider(ctx context.Context, name string) (func(context.Context) error, error) {
 | 
					func newMeterProvider(ctx context.Context, name string) (func(context.Context) error, error) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user