tiny 88x31 lexicon for atproto

i think this should improve cursors on getButtons

+29 -13
+28 -12
db/lexicon.go
··· 9 9 "time" 10 10 ) 11 11 12 - func (s *Store) GetButtonsAuth(limit int, cursor *string, ctx context.Context, did string) ([]types.ButtonViewAuth, time.Time, error) { 12 + func (s *Store) GetButtonsAuth(limit int, cursor *string, ctx context.Context, did string) ([]types.ButtonViewAuth, *time.Time, error) { 13 13 query := ` 14 14 SELECT 15 15 b.uri, ··· 43 43 } 44 44 if err != nil { 45 45 if err == pgx.ErrNoRows { 46 - return nil, time.Time{}, nil 46 + return nil, nil, nil 47 47 } 48 - return nil, time.Time{}, err 48 + return nil, nil, err 49 49 } 50 50 defer rows.Close() 51 51 var buttons = make([]types.ButtonViewAuth, 0) 52 - var postedAt time.Time 52 + var postedAt *time.Time 53 + i := 0 53 54 for rows.Next() { 55 + i = i + 1 56 + if i == limit+1 { 57 + break 58 + } 54 59 var btnView types.ButtonViewAuth 55 60 err := rows.Scan(&btnView.URI, &btnView.DID, &btnView.Alt, &btnView.Title, &btnView.HREF, &postedAt, &btnView.Liked) 56 61 if err != nil { 57 - return nil, time.Time{}, err 62 + return nil, nil, err 58 63 } 59 64 buttons = append(buttons, btnView) 65 + } 66 + if i != limit+1 { 67 + postedAt = nil 60 68 } 61 69 return buttons, postedAt, nil 62 70 } ··· 120 128 return buttons, postedAt, nil 121 129 } 122 130 123 - func (s *Store) GetButtons(limit int, cursor *string, ctx context.Context) ([]types.ButtonView, time.Time, error) { 131 + func (s *Store) GetButtons(limit int, cursor *string, ctx context.Context) ([]types.ButtonView, *time.Time, error) { 124 132 query := ` 125 133 SELECT 126 134 uri, ··· 143 151 var rows pgx.Rows 144 152 var err error 145 153 if cursor != nil { 146 - rows, err = s.pool.Query(ctx, query, limit, cursor) 154 + rows, err = s.pool.Query(ctx, query, limit+1, cursor) 147 155 } else { 148 - rows, err = s.pool.Query(ctx, query, limit) 156 + rows, err = s.pool.Query(ctx, query, limit+1) 149 157 } 150 158 if err != nil { 151 159 if err == pgx.ErrNoRows { 152 - return nil, time.Time{}, nil 160 + return nil, nil, nil 153 161 } 154 - return nil, time.Time{}, err 162 + return nil, nil, err 155 163 } 156 164 defer rows.Close() 157 165 var buttons = make([]types.ButtonView, 0) 158 - var postedAt time.Time 166 + var postedAt *time.Time 167 + i := 0 159 168 for rows.Next() { 169 + i = i + 1 170 + if i == limit+1 { 171 + break 172 + } 160 173 var btnView types.ButtonView 161 174 err := rows.Scan(&btnView.URI, &btnView.CID, &btnView.DID, &btnView.Alt, &btnView.Title, &btnView.HREF, &postedAt) 162 175 if err != nil { 163 - return nil, time.Time{}, err 176 + return nil, nil, err 164 177 } 165 178 buttons = append(buttons, btnView) 179 + } 180 + if i != limit+1 { 181 + postedAt = nil 166 182 } 167 183 return buttons, postedAt, nil 168 184 }
+1 -1
handler/button.go
··· 43 43 myresp.Cursor = nil 44 44 } else { 45 45 myresp.BtnViews = btnViews 46 - myresp.Cursor = &ncursor 46 + myresp.Cursor = ncursor 47 47 } 48 48 err = encoder.Encode(btnViews) 49 49 if err != nil {