Skip to content

Commit

Permalink
fix: avoid memory leak (#558)
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrebruninmaif committed Aug 11, 2021
1 parent d3bf7df commit c0134e5
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions izanami-server/javascript/src/izanami/pages/HomePage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from "react";
import React, {Component} from "react";
import * as IzanamiServices from "../services/index";

class Metric extends Component {
Expand Down Expand Up @@ -49,7 +49,7 @@ class Metric extends Component {
textAlign: "center"
}}
>
<i className={this.props.picto} /> {props.legend}
<i className={this.props.picto}/> {props.legend}
</span>
</div>
</div>
Expand All @@ -72,21 +72,25 @@ export class HomePage extends Component {
this.update();
}

componentWillUnmount() {
if (this.timeout) {
clearTimeout(this.timeout)
this.timeout = null
}
}

update = () => {
IzanamiServices.fetchConfigsCount().then(configsCount => {
IzanamiServices.fetchFeaturesCount().then(featuresCount => {
IzanamiServices.fetchWebHooksCount().then(webHooksCount => {
IzanamiServices.fetchExperimentsCount().then(experimentsCount => {
this.setState(
{ configsCount, featuresCount, webHooksCount, experimentsCount },
() => {
setTimeout(this.update, 60000);
}
);
});
});
});
});
Promise.all([IzanamiServices.fetchConfigsCount(),
IzanamiServices.fetchFeaturesCount(),
IzanamiServices.fetchWebHooksCount(),
IzanamiServices.fetchExperimentsCount()])
.then(([configsCount, featuresCount, webHooksCount, experimentsCount]) => {
this.setState(
{configsCount, featuresCount, webHooksCount, experimentsCount},
() => {
this.timeout = setTimeout(this.update, 60000);
})
})
};

render() {
Expand All @@ -107,7 +111,7 @@ export class HomePage extends Component {
/>
</div>
</div>
<div style={{ marginTop: 80 }}>
<div style={{marginTop: 80}}>
<div
style={{
display: "flex",
Expand Down

0 comments on commit c0134e5

Please sign in to comment.