cached old count and make page fast

This commit is contained in:
Pritimay Sarkar
2023-11-11 15:51:18 +05:30
parent e57ae45596
commit 520fb58c3f

View File

@@ -2,11 +2,17 @@ import './App.css';
import React, { useEffect, useState } from 'react';
import moment from 'moment';
import { collection, onSnapshot, query } from "firebase/firestore";
import { collection, onSnapshot, query, where } from "firebase/firestore";
import Card from './components/Card';
import db from './firebase';
function App() {
const registrationCached = 16329;
const malesCached = 6741;
const femalesCached = 9179;
const normalCached = 7153;
const traitsCached = 2312;
const diseasesCached = 365;
const [totalScreened, setTotalScreened] = useState(0);
const [males, setMales] = useState(0);
const [females, setFemales] = useState(0);
@@ -19,7 +25,8 @@ function App() {
useEffect(() => {
const q = query(collection(db, "patientData"));
// const q = query(collection(db, "patientData")); // cached
const q = query(collection(db, "patientData"), where("testTime", ">=", moment().format("YYYY-MM-DD")));
const unsub = onSnapshot(q, (querySnapshot) => {
const patients = [];
@@ -36,9 +43,9 @@ function App() {
femaleCount++;
}
});
setTotalScreened(patients.length);
setMales(maleCount);
setFemales(femaleCount);
setTotalScreened(registrationCached + patients?.length);
setMales(malesCached + maleCount);
setFemales(femalesCached + femaleCount);
setLastUpdate(moment());
});
@@ -46,7 +53,7 @@ function App() {
}, []);
useEffect(() => {
const q = query(collection(db, "testData"));
const q = query(collection(db, "testData"), where("testTime", ">=", moment().format("YYYY-MM-DD")));
const unsub = onSnapshot(q, (querySnapshot) => {
const hposTests = [];
@@ -68,10 +75,10 @@ function App() {
diseaseCount++;
}
});
setNormal(normalCount);
setNormal(normalCached + normalCount);
// setPositives(traitCount + diseaseCount);
setTraits(traitCount);
setDiseases(diseaseCount);
setTraits(traitsCached + traitCount);
setDiseases(diseasesCached + diseaseCount);
setLastUpdate(moment());
});