API: Fix case with abandoned partial paste
It is possible to abandon a paste while editing it on the web UI, causing the database to have a state that the API was not expecting. This filters out such pastes. When we rewrite the paste.sr.ht frontend to work via GraphQL, we should change the column to non-nullable and remove this where clause.
This commit is contained in:
parent
de46f494b0
commit
f9ccb57940
|
@ -302,7 +302,12 @@ func (r *queryResolver) Pastes(ctx context.Context, cursor *coremodel.Cursor) (*
|
|||
query := database.
|
||||
Select(ctx, paste).
|
||||
From(`paste`).
|
||||
Where(`paste.user_id = ?`, auth.ForContext(ctx).UserID)
|
||||
Where(sq.And{
|
||||
// TODO: Remove this and set the column to non-nullable after
|
||||
// refactoring the frontend to create new pastes via GQL
|
||||
sq.Expr(`paste.sha IS NOT NULL`),
|
||||
sq.Expr(`paste.user_id = ?`, auth.ForContext(ctx).UserID),
|
||||
})
|
||||
pastes, cursor = paste.QueryWithCursor(ctx, tx, query, cursor)
|
||||
return nil
|
||||
}); err != nil {
|
||||
|
@ -331,6 +336,7 @@ func (r *userResolver) Pastes(ctx context.Context, obj *model.User, cursor *core
|
|||
Select(ctx, paste).
|
||||
From(`paste`).
|
||||
Where(sq.And{
|
||||
sq.Expr(`paste.sha IS NOT NULL`),
|
||||
sq.Expr(`paste.user_id = ?`, obj.ID),
|
||||
sq.Or{
|
||||
sq.Expr(`paste.user_id = ?`, auth.ForContext(ctx).UserID),
|
||||
|
|
|
@ -7,11 +7,11 @@ query {
|
|||
me {
|
||||
# Grab their canonical name:
|
||||
canonicalName
|
||||
# And a list of repositories:
|
||||
# And a list of pastes:
|
||||
pastes {
|
||||
# This resource is paginated, so it has a cursor. If you pass this value
|
||||
# into repositories(cursor:"...") in a subsequent request, you'll get the
|
||||
# next page.
|
||||
# into pastes(cursor:"...") in a subsequent request, you'll get the next
|
||||
# page.
|
||||
cursor
|
||||
# These are the actual results. Grab the id, name, and updated fields
|
||||
# from each repository.
|
||||
|
|
Loading…
Reference in New Issue