And even then, the Democratic Republic of Afghanistan, the government that faced Russia, had to fight them back in the 1970s. At such time, the USSR existed, meaning control of Tajikistan, Turkmenistan, Uzbekistan, etc, meaning it COULD invade Afghanistan, which it now can't.
Russia, even if the war ends with Ukrainian victory, will still be able to invade Ukraine.