This commit is contained in:
@@ -98,34 +98,62 @@ jobs:
|
|||||||
SSH_CMD="ssh -i $SSH_KEY -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
|
SSH_CMD="ssh -i $SSH_KEY -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
|
||||||
RSYNC_RSH="ssh -i $SSH_KEY -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
|
RSYNC_RSH="ssh -i $SSH_KEY -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
|
||||||
CHANGE_PATHS=(app/controllers app/middlewares app/models app/routes app/scheduler app/services)
|
CHANGE_PATHS=(app/controllers app/middlewares app/models app/routes app/scheduler app/services)
|
||||||
|
CHANGED_LIST_FILE="$(mktemp)"
|
||||||
|
DELETED_LIST_FILE="$(mktemp)"
|
||||||
|
DIRS_LIST_FILE="$(mktemp)"
|
||||||
|
|
||||||
|
is_excluded_path() {
|
||||||
|
case "$1" in
|
||||||
|
*.DS_Store|*/.DS_Store|_MACOSX|_MACOSX/*|*/_MACOSX|*/_MACOSX/*) return 0 ;;
|
||||||
|
*) return 1 ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
if [ -n "$BEFORE_SHA" ] && [ "$BEFORE_SHA" != "0000000000000000000000000000000000000000" ]; then
|
if [ -n "$BEFORE_SHA" ] && [ "$BEFORE_SHA" != "0000000000000000000000000000000000000000" ]; then
|
||||||
CHANGED_FILES=$(git diff --name-only "$BEFORE_SHA" "$AFTER_SHA" -- "${CHANGE_PATHS[@]}" | rg -v "$EXCLUDE_PATTERN" || true)
|
while IFS= read -r file; do
|
||||||
DELETED_FILES=$(git diff --name-only --diff-filter=D "$BEFORE_SHA" "$AFTER_SHA" -- "${CHANGE_PATHS[@]}" | rg -v "$EXCLUDE_PATTERN" || true)
|
[ -z "$file" ] && continue
|
||||||
|
is_excluded_path "$file" && continue
|
||||||
|
printf '%s\n' "$file" >> "$CHANGED_LIST_FILE"
|
||||||
|
done < <(git diff --name-only --diff-filter=ACMRT "$BEFORE_SHA" "$AFTER_SHA" -- "${CHANGE_PATHS[@]}" || true)
|
||||||
|
|
||||||
|
while IFS= read -r file; do
|
||||||
|
[ -z "$file" ] && continue
|
||||||
|
is_excluded_path "$file" && continue
|
||||||
|
printf '%s\n' "$file" >> "$DELETED_LIST_FILE"
|
||||||
|
done < <(git diff --name-only --diff-filter=D "$BEFORE_SHA" "$AFTER_SHA" -- "${CHANGE_PATHS[@]}" || true)
|
||||||
else
|
else
|
||||||
CHANGED_FILES=$(git show --name-only --pretty="" "$AFTER_SHA" -- "${CHANGE_PATHS[@]}" | rg -v "$EXCLUDE_PATTERN" || true)
|
while IFS= read -r file; do
|
||||||
DELETED_FILES=""
|
[ -z "$file" ] && continue
|
||||||
|
is_excluded_path "$file" && continue
|
||||||
|
[ -f "$file" ] || continue
|
||||||
|
printf '%s\n' "$file" >> "$CHANGED_LIST_FILE"
|
||||||
|
done < <(git show --name-only --pretty="" "$AFTER_SHA" -- "${CHANGE_PATHS[@]}" || true)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$CHANGED_FILES" ]; then
|
if [ ! -s "$CHANGED_LIST_FILE" ]; then
|
||||||
echo "No backend file changes detected in target folders."
|
echo "No backend file changes detected in target folders."
|
||||||
else
|
else
|
||||||
while IFS= read -r file; do
|
while IFS= read -r file; do
|
||||||
[ -z "$file" ] && continue
|
[ -z "$file" ] && continue
|
||||||
[ -f "$file" ] || continue
|
printf '%s\n' "$(dirname "$file")"
|
||||||
remote_file="$REMOTE_APP_ROOT/$file"
|
done < "$CHANGED_LIST_FILE" | awk '!seen[$0]++' > "$DIRS_LIST_FILE"
|
||||||
remote_dir=$(dirname "$remote_file")
|
|
||||||
$SSH_CMD "$REMOTE_USER@$REMOTE_HOST" "sudo mkdir -p \"$remote_dir\""
|
while IFS= read -r dir; do
|
||||||
rsync -az --exclude ".DS_Store" --exclude "_MACOSX" --rsync-path="sudo rsync" -e "$RSYNC_RSH" "$file" "$REMOTE_USER@$REMOTE_HOST:$remote_file"
|
[ -z "$dir" ] && continue
|
||||||
echo "Deployed: $file"
|
$SSH_CMD "$REMOTE_USER@$REMOTE_HOST" "sudo mkdir -p \"$REMOTE_APP_ROOT/$dir\""
|
||||||
done <<< "$CHANGED_FILES"
|
done < "$DIRS_LIST_FILE"
|
||||||
|
|
||||||
|
rsync -az --files-from="$CHANGED_LIST_FILE" --exclude ".DS_Store" --exclude "_MACOSX" --rsync-path="sudo rsync" -e "$RSYNC_RSH" ./ "$REMOTE_USER@$REMOTE_HOST:$REMOTE_APP_ROOT/"
|
||||||
|
echo "Deployed backend changes from CHANGE_PATHS."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$DELETED_FILES" ]; then
|
if [ -s "$DELETED_LIST_FILE" ]; then
|
||||||
while IFS= read -r file; do
|
while IFS= read -r file; do
|
||||||
[ -z "$file" ] && continue
|
[ -z "$file" ] && continue
|
||||||
remote_file="$REMOTE_APP_ROOT/$file"
|
remote_file="$REMOTE_APP_ROOT/$file"
|
||||||
$SSH_CMD "$REMOTE_USER@$REMOTE_HOST" "sudo rm -f \"$remote_file\""
|
$SSH_CMD "$REMOTE_USER@$REMOTE_HOST" "sudo rm -f \"$remote_file\""
|
||||||
echo "Deleted on remote: $file"
|
echo "Deleted on remote: $file"
|
||||||
done <<< "$DELETED_FILES"
|
done < "$DELETED_LIST_FILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
rm -f "$CHANGED_LIST_FILE" "$DELETED_LIST_FILE" "$DIRS_LIST_FILE"
|
||||||
|
|||||||
BIN
app/.DS_Store
vendored
BIN
app/.DS_Store
vendored
Binary file not shown.
@@ -48,8 +48,6 @@ const RoutesDashboard = () => {
|
|||||||
const [routesForShowing, setRoutesForShowing] = useState(allRoutes);
|
const [routesForShowing, setRoutesForShowing] = useState(allRoutes);
|
||||||
const [routesInboundForShowing, setRoutesInboundForShowing] = useState(inboundRoutes);
|
const [routesInboundForShowing, setRoutesInboundForShowing] = useState(inboundRoutes);
|
||||||
const [routesOutboundForShowing, setRoutesOutboundForShowing] = useState(outboundRoutes);
|
const [routesOutboundForShowing, setRoutesOutboundForShowing] = useState(outboundRoutes);
|
||||||
const previousAbsentCustomerIdsRef = useRef(new Set());
|
|
||||||
const isUpdatingAbsentRef = useRef(false);
|
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [errorMessage, setErrorMessage] = useState(undefined);
|
const [errorMessage, setErrorMessage] = useState(undefined);
|
||||||
@@ -481,50 +479,6 @@ const RoutesDashboard = () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Only update backend if absent customer list has changed and not already updating
|
|
||||||
const previousIds = previousAbsentCustomerIdsRef.current;
|
|
||||||
const hasAbsentCustomersChanged =
|
|
||||||
absentCustomerIds.size !== previousIds.size ||
|
|
||||||
[...absentCustomerIds].some(id => !previousIds.has(id)) ||
|
|
||||||
[...previousIds].some(id => !absentCustomerIds.has(id));
|
|
||||||
|
|
||||||
if (hasAbsentCustomersChanged && !isUpdatingAbsentRef.current) {
|
|
||||||
// Update ref immediately (synchronous) to prevent re-entry
|
|
||||||
previousAbsentCustomerIdsRef.current = absentCustomerIds;
|
|
||||||
isUpdatingAbsentRef.current = true;
|
|
||||||
|
|
||||||
// Collect routes that need updating
|
|
||||||
const routesToUpdate = [];
|
|
||||||
outboundRoutes.forEach(outboundRoute => {
|
|
||||||
const filteredCustomerList = outboundRoute.route_customer_list?.filter(customer =>
|
|
||||||
!absentCustomerIds.has(customer.customer_id)
|
|
||||||
) || [];
|
|
||||||
|
|
||||||
if (filteredCustomerList.length !== outboundRoute.route_customer_list?.length) {
|
|
||||||
routesToUpdate.push({
|
|
||||||
id: outboundRoute.id,
|
|
||||||
data: { ...outboundRoute, route_customer_list: filteredCustomerList }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Batch update via direct API calls, then refetch once
|
|
||||||
if (routesToUpdate.length > 0) {
|
|
||||||
Promise.all(routesToUpdate.map(r => TransRoutesService.updateRoute(r.id, r.data)))
|
|
||||||
.then(() => {
|
|
||||||
dispatch(fetchAllRoutes());
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
console.error('Error batch-updating outbound routes:', err);
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
isUpdatingAbsentRef.current = false;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
isUpdatingAbsentRef.current = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove absent customers from outbound routes for display
|
// Remove absent customers from outbound routes for display
|
||||||
const processedOutboundRoutes = outboundRoutes.map(outboundRoute => ({
|
const processedOutboundRoutes = outboundRoutes.map(outboundRoute => ({
|
||||||
...outboundRoute,
|
...outboundRoute,
|
||||||
@@ -534,7 +488,7 @@ const RoutesDashboard = () => {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
return processedOutboundRoutes;
|
return processedOutboundRoutes;
|
||||||
}, [dispatch, fetchAllRoutes])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setPageLoading(true);
|
setPageLoading(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user