daisycrego / jbg-admin

Admin app for Jill Biggs Group follow-up boss event management
1 stars 0 forks source link

Homepage loading slowly - too many events #15

Closed daisycrego closed 3 years ago

daisycrego commented 3 years ago

Now that there are >1000 events, the render of the EventsTable is getting slow.

Solutions

daisycrego commented 3 years ago

The issue is possibly the call to stableSort on all ~1100 rows:

<TableBody>
  {stableSort(rows, getComparator(order, orderBy))
    .slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
    .map((row, index) => {
      const labelId = `enhanced-table-checkbox-${index}`;

      return (
        <TableRow hover tabIndex={-1} key={row._id}>
          <TableCell
            component="th"
            id={labelId}
            scope="row"
            align={"default"}
            padding={"left"}
          >
            {row.property ? row.property.street : ""}
          </TableCell>
          <TableCell align={"default"} padding={"left"}>
            {`${new Date(row.created).toDateString()} ${new Date(
              row.created
            ).toLocaleTimeString()}`}
          </TableCell>
          <TableCell align={"default"} padding={"left"}>
            {row.source}
          </TableCell>
          <TableCell align={"default"} padding={"left"}>
            {data(row)}
          </TableCell>
          <TableCell align={"default"} padding={"left"}>
            <Link to={"/event/" + row._id} key={row._id}>
              <IconButton>
                <ArrowForward />
              </IconButton>
            </Link>
          </TableCell>
        </TableRow>
      );
    })}
  {emptyRows > 0 && (
    <TableRow style={{ height: (dense ? 33 : 53) * emptyRows }}>
      <TableCell colSpan={6} />
    </TableRow>
  )}
</TableBody>
daisycrego commented 3 years ago

SOLUTION

{ activeRows.map((row, index) => { ...
daisycrego commented 3 years ago

Not 100% on this, but it seems that defining activeRows in the component body instead of as embedded javascript is allowing us to spend time fetching the activeRows before the user ever sees the page. I think that in the previous implementation, the sorting functions are effectively initiated when the component renders, rather than before.