Skip to content

Add pagination to admin user activity endpoint #539

Open

Description

@DeFiVC

Bug Description

The getUserActivity method in src/modules/admin/admin-users.service.ts (lines 267-357) queries multiple tables without pagination, returning ALL activity records for a user. For long-tenured users, this could return thousands of records.

Location

src/modules/admin/admin-users.service.ts lines 267-357

async getUserActivity(userId: string): Promise<
    Array<{
        type: string;
        title: string;
        timestamp: Date;
        details: Record<string, unknown>;
    }>
> {
    // Fetch all activity sources - NO PAGINATION
    const [enrollmentRows, submissionRows, credentialRows] = await Promise.all([
        db.select()...from(enrollments)...where(eq(enrollments.userId, userId)),
        db.select()...from(quizSubmissions)...where(eq(quizSubmissions.userId, userId)),
        db.select()...from(credentials)...where(eq(credentials.userId, userId)),
    ]);
    // ... combines all and sorts
}

The Problem

  1. No pagination - returns ALL records
  2. For active users, this could be hundreds of enrollments, thousands of quiz submissions
  3. The response is unbounded and could be very large
  4. No limit on the number of records returned from each table
  5. Combines all results in memory, sorts, and returns everything

Recommended Fix

Add pagination parameters and limit the query:

async getUserActivity(
    userId: string,
    page: number = 1,
    limit: number = 50
): Promise<{ activities: Activity[]; total: number }> {
    const offset = (page - 1) * limit;

    // Use UNION ALL query or limit each source
    // ... with pagination
}

Acceptance Criteria

  • Add pagination parameters (page, limit) to the method
  • Limit the number of records returned from each table
  • Return total count for pagination metadata
  • Consider using a UNION ALL query for efficiency

Severity

medium - Performance issue that could cause timeouts or memory issues for active users.

Activity

  1. guptakumarranjeet150 commented on Sep 30, 2026

    @guptakumarranjeet150

    Hey maintainers,

    I can tackle Add pagination to admin user activity endpoint. Proposed implementation roadmap:

    • Analysis: Inspect current behavior and edge cases in ChainLearnOfficial/chainlearn-api
    • Core Implementation: Build out the handlers for Add pagination to admin user activity endpoint ensuring proper HTTP status codes and error propagation.
    • Quality Assurance: Verify API response schemas, authentication middleware, and database rollback safety.

    I am ready to start immediately—please feel free to assign this to me!

  2. samueldoo commented on Sep 30, 2026

    @samueldoo

    Hi Maintainers, I’d like to work on resolving this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions