rate limiting
This commit is contained in:
@@ -23,6 +23,7 @@ const Applications = () => {
|
||||
const [nozzles, setNozzles] = useState([]);
|
||||
const [selectedPropertyDetails, setSelectedPropertyDetails] = useState(null);
|
||||
const [editingPlan, setEditingPlan] = useState(null);
|
||||
const [propertyCache, setPropertyCache] = useState({});
|
||||
|
||||
useEffect(() => {
|
||||
fetchApplications();
|
||||
@@ -76,9 +77,18 @@ const Applications = () => {
|
||||
};
|
||||
|
||||
const fetchPropertyDetails = async (propertyId) => {
|
||||
// Check cache first
|
||||
if (propertyCache[propertyId]) {
|
||||
setSelectedPropertyDetails(propertyCache[propertyId]);
|
||||
return propertyCache[propertyId];
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await propertiesAPI.getById(parseInt(propertyId));
|
||||
const property = response.data.data.property;
|
||||
|
||||
// Cache the result
|
||||
setPropertyCache(prev => ({ ...prev, [propertyId]: property }));
|
||||
setSelectedPropertyDetails(property);
|
||||
return property;
|
||||
} catch (error) {
|
||||
@@ -385,11 +395,8 @@ const ApplicationPlanModal = ({
|
||||
|
||||
// Initialize form with editing data
|
||||
useEffect(() => {
|
||||
if (editingPlan) {
|
||||
if (editingPlan && products.length > 0) {
|
||||
const propertyId = editingPlan.section?.propertyId || editingPlan.property?.id;
|
||||
if (propertyId && propertyId !== planData.propertyId) {
|
||||
onPropertySelect(propertyId);
|
||||
}
|
||||
|
||||
// Find the product from the plans products array
|
||||
const planProduct = editingPlan.products?.[0];
|
||||
@@ -413,12 +420,17 @@ const ApplicationPlanModal = ({
|
||||
plannedDate: editingPlan.plannedDate ? new Date(editingPlan.plannedDate).toISOString().split('T')[0] : '',
|
||||
notes: editingPlan.notes || ''
|
||||
});
|
||||
|
||||
// Only fetch property details if we don't already have them
|
||||
if (propertyId && (!selectedPropertyDetails || selectedPropertyDetails.id !== propertyId)) {
|
||||
onPropertySelect(propertyId);
|
||||
}
|
||||
}
|
||||
}, [editingPlan, products, onPropertySelect]);
|
||||
}, [editingPlan, products]);
|
||||
|
||||
const handlePropertyChange = async (propertyId) => {
|
||||
setPlanData({ ...planData, propertyId, selectedAreas: [] });
|
||||
if (propertyId) {
|
||||
if (propertyId && propertyId !== selectedPropertyDetails?.id?.toString()) {
|
||||
setLoadingProperty(true);
|
||||
await onPropertySelect(propertyId);
|
||||
setLoadingProperty(false);
|
||||
|
||||
Reference in New Issue
Block a user