refactor: optimize socket connection handling by removing polling transport and implementing lazy connection strategy in SocketManager for improved performance
This commit is contained in:
@@ -20,14 +20,14 @@ class CartItem extends Component {
|
||||
this.setState({image:window.tinyPicCache[picid],loading:false, error: false})
|
||||
}else{
|
||||
this.setState({image: null, loading: true, error: false});
|
||||
if(this.props.socket && this.props.socket.connected){
|
||||
//if(this.props.socket && this.props.socket.connected){
|
||||
this.props.socket.emit('getPic', { bildId:picid, size:'tiny' }, (res) => {
|
||||
if(res.success){
|
||||
window.tinyPicCache[picid] = URL.createObjectURL(new Blob([res.imageBuffer], { type: 'image/jpeg' }));
|
||||
this.setState({image: window.tinyPicCache[picid], loading: false});
|
||||
}
|
||||
})
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ const CategoryBox = ({
|
||||
}
|
||||
|
||||
// If socket is available and connected, fetch the image
|
||||
if (context && context.socket && context.socket.connected && id && !isLoading) {
|
||||
if (context && context.socket /*&& context.socket.connected*/ && id && !isLoading) {
|
||||
setIsLoading(true);
|
||||
|
||||
context.socket.emit('getCategoryPic', { categoryId: id }, (response) => {
|
||||
|
||||
@@ -278,12 +278,12 @@ class Content extends Component {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.props.socket || !this.props.socket.connected) {
|
||||
//if (!this.props.socket || !this.props.socket.connected) {
|
||||
// Socket not connected yet, but don't show error immediately on first load
|
||||
// The componentDidUpdate will retry when socket connects
|
||||
console.log("Socket not connected yet, waiting for connection to fetch category data");
|
||||
return;
|
||||
}
|
||||
// console.log("Socket not connected yet, waiting for connection to fetch category data");
|
||||
// return;
|
||||
//}
|
||||
console.log(`productList:${categoryId}`);
|
||||
this.props.socket.off(`productList:${categoryId}`);
|
||||
|
||||
@@ -365,12 +365,12 @@ class Content extends Component {
|
||||
}
|
||||
|
||||
fetchSearchData(query) {
|
||||
if (!this.props.socket || !this.props.socket.connected) {
|
||||
// if (!this.props.socket || !this.props.socket.connected) {
|
||||
// Socket not connected yet, but don't show error immediately on first load
|
||||
// The componentDidUpdate will retry when socket connects
|
||||
console.log("Socket not connected yet, waiting for connection to fetch search data");
|
||||
return;
|
||||
}
|
||||
// console.log("Socket not connected yet, waiting for connection to fetch search data");
|
||||
// return;
|
||||
// }
|
||||
|
||||
this.props.socket.emit("getSearchProducts", { query },
|
||||
(response) => {
|
||||
|
||||
@@ -230,10 +230,10 @@ class ProductDetailPage extends Component {
|
||||
}
|
||||
|
||||
// If not cached, fetch from server (similar to loadProductData)
|
||||
if (!this.props.socket || !this.props.socket.connected) {
|
||||
console.log("Socket not connected yet, waiting for connection to load komponent data");
|
||||
return;
|
||||
}
|
||||
//if (!this.props.socket || !this.props.socket.connected) {
|
||||
// console.log("Socket not connected yet, waiting for connection to load komponent data");
|
||||
// return;
|
||||
//}
|
||||
|
||||
// Mark this komponent as loading
|
||||
this.setState(prevState => ({
|
||||
|
||||
@@ -148,8 +148,8 @@ class ProductSelector extends Component {
|
||||
return (
|
||||
<Box sx={{ mb: 4 }}>
|
||||
<Typography variant="h2" component="h2" gutterBottom sx={{ color: '#2e7d32', fontWeight: 'bold' }}>
|
||||
{title}
|
||||
</Typography>
|
||||
{title}
|
||||
</Typography>
|
||||
{subtitle && (
|
||||
<Typography variant="body1" color="text.secondary" sx={{ mb: 3 }}>
|
||||
{subtitle}
|
||||
|
||||
@@ -181,8 +181,6 @@ class CategoryList extends Component {
|
||||
fetchCategories = () => {
|
||||
const { socket } = this.props;
|
||||
if (!socket || !socket.connected) {
|
||||
// Socket not connected yet, but don't show error immediately on first load
|
||||
// The componentDidUpdate will retry when socket connects
|
||||
console.log("Socket not connected yet, waiting for connection to fetch categories");
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user