Просмотр исходного кода

perf(ui): Prevent unnecessary endpoint requests (#28924)

Objective:
Identify and remove duplicate API queries by our frontend client for our slowest pages. One endpoint that gets called multiple times unnecessarily is /api/0/projects/{organization_slug}/{project_slug}/. P95 for this query is 334.00ms. This is the low hanging fruit for page speed optimization.
NisanthanNanthakumar 3 лет назад
Родитель
Сommit
493559e6df
1 измененных файлов с 8 добавлено и 2 удалено
  1. 8 2
      static/app/views/projects/projectContext.tsx

+ 8 - 2
static/app/views/projects/projectContext.tsx

@@ -39,6 +39,7 @@ type Props = {
   projectId: string;
   orgId: string;
   children: ((props: ChildFuncProps) => React.ReactNode) | React.ReactNode;
+  loadingProjects: boolean;
 };
 
 type State = {
@@ -79,8 +80,13 @@ class ProjectContext extends Component<Props, State> {
     };
   }
 
-  componentWillMount() {
-    this.fetchData();
+  componentDidMount() {
+    // Wait for withProjects to fetch projects before making request
+    // Once loaded we can fetchData in componentDidUpdate
+    const {loadingProjects} = this.props;
+    if (!loadingProjects) {
+      this.fetchData();
+    }
   }
 
   componentWillReceiveProps(nextProps: Props) {