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

added rate limits to each room by author group and author #245

Merged
merged 10 commits into from
Nov 7, 2024

Conversation

FrederickPu
Copy link
Contributor

added rate limits on the number of pending requests for on a room for each user and group

Note: still have not created a constant for the maximum number of pending requests (it's a hardcoded value).

@FrederickPu FrederickPu marked this pull request as ready for review November 6, 2024 05:00
@FrederickPu
Copy link
Contributor Author

#148

@ggggg ggggg linked an issue Nov 6, 2024 that may be closed by this pull request
@ggggg
Copy link
Collaborator

ggggg commented Nov 6, 2024

Ideally, we would make it into a per-room setting in the future. Unfortunately, room settings arent really a thing right now...

@ggggg
Copy link
Collaborator

ggggg commented Nov 6, 2024

The original issue does state that limits should be "per room." If you could make that change, it'd be great!

@FrederickPu
Copy link
Contributor Author

The original issue does state that limits should be "per room." If you could make that change, it'd be great!
Isn't it already doing that since the db request already only finds pending requests with the current room name?

@ggggg
Copy link
Collaborator

ggggg commented Nov 6, 2024

Sorry, I meant configured per room, as in, making an adjustable setting for each room

@FrederickPu
Copy link
Contributor Author

FrederickPu commented Nov 6, 2024

so you mean change the db so that the admin can configure per room limits?

@ggggg ggggg self-requested a review November 6, 2024 17:02
@ggggg ggggg changed the base branch from main to develop November 6, 2024 17:02
Comment on lines 269 to 275
const pendingUser = await db.request.findMany({
where: {
authorUtorid: user.utorid,
status: RequestStatus.pending,
roomName: request.roomName,
}
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

This info can be fetched when fetching this user, try limiting the number of DB queries

Comment on lines 283 to 289
const pendingGroup = await db.request.findMany({
where: {
groupId: request.groupId,
status: RequestStatus.pending,
roomName: request.roomName,
}
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as the other comment

roomName: request.roomName,
}
})
if (pendingUser.length > (room?.capacity || 10)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (pendingUser.length > (room?.capacity || 10)) {
if (pendingUser.length > (room?.requestLimit || 10)) {

roomName: request.roomName,
}
})
if (pendingGroup.length > (room?.capacity || 10)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (pendingGroup.length > (room?.capacity || 10)) {
if (pendingGroup.length > (room?.requestLimit || 10)) {

}
if (userFetched.requests.length > room.requestLimit) {
return {
status: 403,
Copy link
Member

Choose a reason for hiding this comment

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

should this be http 429


if (groupFetched.requests.length > room.requestLimit) {
return {
status: 403,
Copy link
Member

Choose a reason for hiding this comment

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

should this be http 429: too many requests

Comment on lines +287 to +299
if (userFetched.requests.length >= room.requestLimit) {
return {
status: 429,
message: 'User has too many pending requests.',
}
}
if (userFetched.groups[0].requests.length >= room.requestLimit) {
return {
status: 429,
message: 'Group has too many pending requests.',
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (userFetched.requests.length >= room.requestLimit) {
return {
status: 429,
message: 'User has too many pending requests.',
}
}
if (userFetched.groups[0].requests.length >= room.requestLimit) {
return {
status: 429,
message: 'Group has too many pending requests.',
}
}
if (userFetched.requests.length >= room.requestLimit || userFetched.groups[0].requests.length >= room.requestLimit) {
return {
status: 429,
message: 'User has too many pending requests.',
}
}

@ggggg ggggg requested a review from logonoff November 7, 2024 03:04
@ggggg ggggg merged commit e3d4d8d into utmgdsc:develop Nov 7, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ratelimits per room for bookings
3 participants