Skip to content

Commit

Permalink
removed stats from byforapproval.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed Sep 27, 2024
1 parent 07b28f6 commit 06e5523
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 45 deletions.
3 changes: 1 addition & 2 deletions handler/app/internal/fileslice/fileslice.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ func Records(ctx context.Context, exec boil.ContextExecutor, uri string, page, l
switch Match(uri) {
// pulldown editor menu matches
case ForApproval:
r := model.Artifacts{}
return r.ByForApproval(ctx, exec, page, limit)
return model.ByForApproval(ctx, exec, page, limit)
case Deletions:
r := model.Artifacts{}
return r.ByHidden(ctx, exec, page, limit)
Expand Down
62 changes: 20 additions & 42 deletions model/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ package model
import (
"context"
"fmt"
"io"
"os"

"github.com/Defacto2/server/internal/postgres"
"github.com/Defacto2/server/internal/postgres/models"
Expand Down Expand Up @@ -149,46 +147,6 @@ func (f *Artifacts) byHidden(ctx context.Context, exec boil.ContextExecutor) err
qm.From(From)).Bind(ctx, exec, f)
}

// ByForApproval returns all of the file records that are waiting to be marked for approval.
func (f *Artifacts) ByForApproval(ctx context.Context, exec boil.ContextExecutor, offset, limit int) (
models.FileSlice, error,
) {
if invalidExec(exec) {
return nil, ErrDB
}
fmt.Fprintln(os.Stderr, "========================ByForApproval===============================")
boil.DebugMode = true // TODO: remove this debug line
if err := f.byForApproval(ctx, exec); err != nil {
fmt.Fprintln(os.Stderr, "BYFORAPPROVAL", err)
fmt.Fprint(io.Discard, err)
return nil, nil
}
fmt.Fprintln(os.Stderr, "B", f.Bytes, "C", f.Count)
const clause = "id DESC"
return models.Files(
qm.WithDeleted(),
models.FileWhere.Deletedat.IsNotNull(),
models.FileWhere.Deletedby.IsNull(),
qm.OrderBy(clause),
qm.Offset(calc(offset, limit)),
qm.Limit(limit)).All(ctx, exec)
}

func (f *Artifacts) byForApproval(ctx context.Context, exec boil.ContextExecutor) error {
if invalidExec(exec) {
return ErrDB
}
if f.Bytes > 0 && f.Count > 0 {
return nil
}
return models.NewQuery(
qm.WithDeleted(),
models.FileWhere.Deletedat.IsNotNull(),
models.FileWhere.Deletedby.IsNull(),
qm.Select(postgres.Columns()...),
qm.From(From)).Bind(ctx, exec, f)
}

// ByMagicErr returns all of the file records that require new magic numbers.
func (f *Artifacts) ByMagicErr(ctx context.Context, exec boil.ContextExecutor, binaryData bool) (
models.FileSlice, error,
Expand Down Expand Up @@ -375,3 +333,23 @@ func (f *Artifacts) ID(
}
return fs, nil
}

// ByForApproval returns all of the file records that are waiting to be marked for approval.
//
// This should not bind values to Artifacts struct as it can fail with a scan error due to unapproved files
// missing bytes and minyear/maxyear values.
func ByForApproval(ctx context.Context, exec boil.ContextExecutor, offset, limit int) (
models.FileSlice, error,
) {
if invalidExec(exec) {
return nil, ErrDB
}
const clause = "id DESC"
return models.Files(
qm.WithDeleted(),
models.FileWhere.Deletedat.IsNotNull(),
models.FileWhere.Deletedby.IsNull(),
qm.OrderBy(clause),
qm.Offset(calc(offset, limit)),
qm.Limit(limit)).All(ctx, exec)
}
2 changes: 1 addition & 1 deletion model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func TestArtifacts(t *testing.T) {
x, err = a.ByHidden(ctx, nil, -1, -1)
assert.Nil(t, x)
require.Error(t, err)
x, err = a.ByForApproval(ctx, nil, -1, -1)
x, err = model.ByForApproval(ctx, nil, -1, -1)
assert.Nil(t, x)
require.Error(t, err)
x, err = a.ByMagicErr(ctx, nil, true)
Expand Down

0 comments on commit 06e5523

Please sign in to comment.