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

feat: mutiple incidents #4986

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dist
dist-ssr
*.local
.idea
.history/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could not find good docs what the folder does.
What does this ignore do?

Suggested change
.history/


/data
!/data/.gitkeep
Expand Down
37 changes: 27 additions & 10 deletions server/model/status_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,10 @@ class StatusPage extends BeanModel {
static async getStatusPageData(statusPage) {
const config = await statusPage.toPublicJSON();

// Incident
let incident = await R.findOne("incident", " pin = 1 AND active = 1 AND status_page_id = ? ", [
statusPage.id,
]);

if (incident) {
incident = incident.toPublicJSON();
}
// Incident List
const incidentList = await StatusPage.getIncidentList(statusPage.id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

In cases such as these two lines, please use Promise.all() to not await twice (=a bit faster)

We know that this is an issue accross the app and that performance could be improved this way ^^


let maintenanceList = await StatusPage.getMaintenanceList(statusPage.id);
const maintenanceList = await StatusPage.getMaintenanceList(statusPage.id);

// Public Group List
const publicGroupList = [];
Expand All @@ -133,7 +127,7 @@ class StatusPage extends BeanModel {
// Response
return {
config,
incident,
incidentList,
publicGroupList,
maintenanceList,
};
Expand Down Expand Up @@ -329,6 +323,29 @@ class StatusPage extends BeanModel {
return [];
}
}

/**
* Get list of incidents
* @param {number} statusPageId ID of status page to get incidents for
* @returns {object} Object representing incidents sanitized for public
*/
static async getIncidentList(statusPageId) {
try {
const publicIncidentList = [];
let incidentList = await R.find("incident", " pin = 1 AND active = 1 AND status_page_id = ? ", [
statusPageId,
]);

for (const incident of incidentList) {
publicIncidentList.push(await incident.toPublicJSON());
}

return publicIncidentList;

} catch (error) {
return [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you add a warning log here? (seems scarry to just ignore the error, I know that you did it to match the above)

}
}
}

module.exports = StatusPage;
11 changes: 4 additions & 7 deletions server/socket-handlers/status-page-socket-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ module.exports.statusPageSocketHandler = (socket) => {
throw new Error("slug is not found");
}

await R.exec("UPDATE incident SET pin = 0 WHERE status_page_id = ? ", [
statusPageID
]);

let incidentBean;

if (incident.id) {
Expand Down Expand Up @@ -69,14 +65,15 @@ module.exports.statusPageSocketHandler = (socket) => {
}
});

socket.on("unpinIncident", async (slug, callback) => {
socket.on("unpinIncident", async (slug, incident, callback) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please change this to be just the incidentId, as incident.id is the only part from this which is used

try {
checkLogin(socket);

let statusPageID = await StatusPage.slugToID(slug);

await R.exec("UPDATE incident SET pin = 0 WHERE pin = 1 AND status_page_id = ? ", [
statusPageID
await R.exec("UPDATE incident SET pin = 0 WHERE pin = 1 AND status_page_id = ? AND id = ? ", [
statusPageID,
incident.id
]);

callback({
Expand Down
Loading
Loading