Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit actors loaded on queue (re)load #144

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/moderation.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ func (m *ModerationServiceHandler) ListActors(ctx context.Context, req *connect.

actors, err := m.store.ListActors(ctx, store.ListActorsOpts{
FilterStatus: req.Msg.FilterStatus,
Limit: req.Msg.Limit,
})
if err != nil {
return nil, fmt.Errorf("listing actors: %w", err)
Expand Down
14 changes: 10 additions & 4 deletions store/gen/candidate_actors.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion store/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func (s *PGXStore) TX(ctx context.Context) (*PGXTX, error) {

type ListActorsOpts struct {
FilterStatus v1.ActorStatus
Limit int32
}

func (s *PGXStore) ListActors(ctx context.Context, opts ListActorsOpts) (out []*v1.Actor, err error) {
Expand All @@ -178,7 +179,10 @@ func (s *PGXStore) ListActors(ctx context.Context, opts ListActorsOpts) (out []*
statusFilter.ActorStatus = status
}

actors, err := s.queries.ListCandidateActors(ctx, statusFilter)
actors, err := s.queries.ListCandidateActors(ctx, gen.ListCandidateActorsParams{
Status: statusFilter,
Limit: opts.Limit,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change breaks the CandidateActorCache as that hasn't been updated to pass a limit in - so 0 will be used. We may need to build pagination into that before we can do this 😓

})
if err != nil {
return nil, fmt.Errorf("executing ListCandidateActors query: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion store/queries/candidate_actors.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ WHERE
(sqlc.narg(status)::actor_status IS NULL OR
ca.status = @status)
ORDER BY
did;
did
LIMIT $1;

-- name: CreateCandidateActor :one
INSERT INTO
Expand Down
2 changes: 1 addition & 1 deletion web/admin/components/user-queue-actions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function process(did: string, action: ApprovalQueueAction) {
>
<span class="md:ml-auto max-md:w-full flex items-baseline">
<span v-if="pending" class="text-xs text-gray-700 mx-1">
({{ pending }} more...)
({{ pending > 100 ? "100+" : pending }} more...)
</span>
<button
class="py-0.5 px-2 max-md:ml-auto mr-1 text-white bg-blue-500 dark:bg-blue-600 rounded-lg hover:bg-blue-600 dark:hover:bg-blue-700 disabled:bg-blue-300 disabled:dark:bg-blue-500 disabled:cursor-not-allowed"
Expand Down
6 changes: 5 additions & 1 deletion web/admin/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ const pending = ref(0);
const actor = ref<Actor>();

const nextActor = async () => {
const queue = await api.listActors({ filterStatus: ActorStatus.PENDING });
const queue = await api.listActors({
filterStatus: ActorStatus.PENDING,
limit: 102,
});

pending.value = queue.actors.length - 1;
actor.value = queue.actors[0];
};
Expand Down