tangled
alpha
login
or
join now
moth11.net
/
88x31
0
fork
atom
tiny 88x31 lexicon for atproto
0
fork
atom
overview
issues
pulls
pipelines
i think this should improve cursors on getButtons
moth11.net
1 month ago
4633b7d4
fa12e0fa
+29
-13
2 changed files
expand all
collapse all
unified
split
db
lexicon.go
handler
button.go
+28
-12
db/lexicon.go
···
9
9
"time"
10
10
)
11
11
12
12
-
func (s *Store) GetButtonsAuth(limit int, cursor *string, ctx context.Context, did string) ([]types.ButtonViewAuth, time.Time, error) {
12
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
46
-
return nil, time.Time{}, nil
46
46
+
return nil, nil, nil
47
47
}
48
48
-
return nil, time.Time{}, err
48
48
+
return nil, nil, err
49
49
}
50
50
defer rows.Close()
51
51
var buttons = make([]types.ButtonViewAuth, 0)
52
52
-
var postedAt time.Time
52
52
+
var postedAt *time.Time
53
53
+
i := 0
53
54
for rows.Next() {
55
55
+
i = i + 1
56
56
+
if i == limit+1 {
57
57
+
break
58
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
57
-
return nil, time.Time{}, err
62
62
+
return nil, nil, err
58
63
}
59
64
buttons = append(buttons, btnView)
65
65
+
}
66
66
+
if i != limit+1 {
67
67
+
postedAt = nil
60
68
}
61
69
return buttons, postedAt, nil
62
70
}
···
120
128
return buttons, postedAt, nil
121
129
}
122
130
123
123
-
func (s *Store) GetButtons(limit int, cursor *string, ctx context.Context) ([]types.ButtonView, time.Time, error) {
131
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
146
-
rows, err = s.pool.Query(ctx, query, limit, cursor)
154
154
+
rows, err = s.pool.Query(ctx, query, limit+1, cursor)
147
155
} else {
148
148
-
rows, err = s.pool.Query(ctx, query, limit)
156
156
+
rows, err = s.pool.Query(ctx, query, limit+1)
149
157
}
150
158
if err != nil {
151
159
if err == pgx.ErrNoRows {
152
152
-
return nil, time.Time{}, nil
160
160
+
return nil, nil, nil
153
161
}
154
154
-
return nil, time.Time{}, err
162
162
+
return nil, nil, err
155
163
}
156
164
defer rows.Close()
157
165
var buttons = make([]types.ButtonView, 0)
158
158
-
var postedAt time.Time
166
166
+
var postedAt *time.Time
167
167
+
i := 0
159
168
for rows.Next() {
169
169
+
i = i + 1
170
170
+
if i == limit+1 {
171
171
+
break
172
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
163
-
return nil, time.Time{}, err
176
176
+
return nil, nil, err
164
177
}
165
178
buttons = append(buttons, btnView)
179
179
+
}
180
180
+
if i != limit+1 {
181
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
46
-
myresp.Cursor = &ncursor
46
46
+
myresp.Cursor = ncursor
47
47
}
48
48
err = encoder.Encode(btnViews)
49
49
if err != nil {