-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
Ideally, we would make it into a per-room setting in the future. Unfortunately, room settings arent really a thing right now... |
The original issue does state that limits should be "per room." If you could make that change, it'd be great! |
|
Sorry, I meant configured per room, as in, making an adjustable setting for each room |
so you mean change the db so that the admin can configure per room limits? |
backend/src/models/requestsModel.ts
Outdated
const pendingUser = await db.request.findMany({ | ||
where: { | ||
authorUtorid: user.utorid, | ||
status: RequestStatus.pending, | ||
roomName: request.roomName, | ||
} | ||
}) |
There was a problem hiding this comment.
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
backend/src/models/requestsModel.ts
Outdated
const pendingGroup = await db.request.findMany({ | ||
where: { | ||
groupId: request.groupId, | ||
status: RequestStatus.pending, | ||
roomName: request.roomName, | ||
} | ||
}) |
There was a problem hiding this comment.
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
backend/src/models/requestsModel.ts
Outdated
roomName: request.roomName, | ||
} | ||
}) | ||
if (pendingUser.length > (room?.capacity || 10)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (pendingUser.length > (room?.capacity || 10)) { | |
if (pendingUser.length > (room?.requestLimit || 10)) { |
backend/src/models/requestsModel.ts
Outdated
roomName: request.roomName, | ||
} | ||
}) | ||
if (pendingGroup.length > (room?.capacity || 10)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (pendingGroup.length > (room?.capacity || 10)) { | |
if (pendingGroup.length > (room?.requestLimit || 10)) { |
…ckPu/hacklab-booking into add-rate-limits-per-room
backend/src/models/requestsModel.ts
Outdated
} | ||
if (userFetched.requests.length > room.requestLimit) { | ||
return { | ||
status: 403, |
There was a problem hiding this comment.
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
backend/src/models/requestsModel.ts
Outdated
|
||
if (groupFetched.requests.length > room.requestLimit) { | ||
return { | ||
status: 403, |
There was a problem hiding this comment.
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
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.', | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.', | |
} | |
} | |
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).