windyScripts / dev-directory

21 stars 5 forks source link

Tech spec: Pagination #7

Closed DevinCLane closed 1 year ago

DevinCLane commented 1 year ago

Summary: This tech spec outlines the technical requirements for implementing pagination on Dev Directory

Scope: Define the scope of the project, including what it will and will not include. List the features, functions, and requirements of the project.

Data model: Define the data model of the project, including the database schema and relationships between data entities. Describe how the data will be stored, accessed, and updated.

No changes needed to the data model. This tech spec is only responsible for reading from the DB.

User Stories: List the ways the user will interact with the project. e.g. "User will be able to edit their profile."

  1. User lands on pagination page with a random assortment of developers within Dev directory, most likely 8.
  2. As the user filters, profiles are removed/added to the page, results should be randomized to provide diversity.
  3. Results should be randomized such that multiple requests for results with same filters produce different results. However, if there are more results than viewable slots, it should not be randomized on every addition of a filter. For example, if half of the currently rendered profiles fit with the next applied filter they should not be removed because of randomness.

User has the option to load more, and can either click "load more" and scroll, or infinite scroll is triggered by scrolling down.

Implementation: Describe how the features are implememented

Select *
FROM users
WHERE ID > <since_id_param>
ORDER BY ID ASC
LIMIT 100

APIs: Define the APIs of the project, including the endpoints, methods, and request/response formats. Describe how the APIs will be documented, tested, and secured.

The directory API will be used to retrieve the dataset to be paginated and to load each page of items when a user navigates to a new page. The API will also be used to calculate the total number of pages based on the number of items per page and the total number of items in the dataset. (adapted from chatGPT)

Security: Describe the security features and requirements of the project, including authentication, authorization, encryption, and data protection.

Testing: Describe the testing approach and strategy for the project, including unit tests, integration tests, and end-to-end tests. Describe how the tests will be automated and integrated into the development process.

Open Questions: Use this space to ask any questions of which you're not sure of the answer, whether it be a technical question or an implementation detail.

Deployment: Describe any special considerations needed when deploying the project. For example, if there are breaking schema changes, how do we migrate existing data?

MainlyColors commented 1 year ago

For the random implementation (line below) what guarantees on page 2 that a user from page 1 isn't selected again when randomly selecting from the DB?

const res = await client.query('SELECT * FROM users ORDER BY random() LIMIT 8');
Caleb-Cohen commented 1 year ago
  • GET /api/users/:id should not return the discord_name if the caller is not authed

Good question. This logic should only apply to initial page loads. I don't want the same 8 profiles being shown to everyone the first time the page is loaded.

There will need to be more complex logic for the infinity scroll such that profiles are not randomly selected again in the scrolling process.

timmyichen commented 1 year ago

@DevinCLane can you repost this to Discussions? Realizing we should be using that for discussions and once finalized, move to here for referencing.

https://github.com/timmyichen/dev-directory/discussions/new?category=technical-specification-review

Caleb-Cohen commented 1 year ago

@DevinCLane I want to walk back the randomness. I think this will add complexity and solve a problem we won't even have with MVP due to limited users.

I'd recommend lowering the complexity and setting pagination to just a sort of some default criteria.

DevinCLane commented 1 year ago

Okay moving this over to Discussions.

timmyichen commented 1 year ago

Closed via #17