Sugar and Immunity

Can anyone tell me why sugar helps to maintain immunity post exercise, but is linked to a lower immunity when consumed in excess during other ‘timeframes’? It’s interesting to know why the body responds differently to the the same nutrient at different times.

Does ‘sugar’ illicit different biochemical effects on the immune system if excess sugar is consumed? This would make some sense, since ‘sugar’ illicits positive effects on muscle gain/recovery post exercise, and negative effects when consumed in excess at other times.