Is anyone on medication to prevent UTIs from sex?

I’m immune compromised and very prone to infections. I had 7-8 utis in a year and finally my doctor put me on a medication that I take before sex to help prevent a uti. I was still doing all things you’re supposed like keeping clean, using the right soaps, and peeing afterwards but would still get them. Does anyone have a similar experience? I hate that we can’t have spontaneous sex anymore but its great to not have a constant uti after almost a year and half.