Naya Rivera isn’t sorry she and Mark Salling didn’t work out, especially after he was busted on child pornography charges.

In her memoir, “Sorry Not Sorry: Dreams, Mistakes and Growing Up,” Rivera, 29, explains how she learned of the disturbing allegations against her ex.

“My son’s nanny actually told me about it when the story broke,” she wrote. “I can’t say I was totally shocked, but still — WTF? Then I had no doubt that God really did have my back along the way. When Mark dumped me, I thought it was the worst thing ever, but can you imagine if that didn’t happen? And I was laying there in bed when the battering ram came through the door?”

The former “Glee” co-stars had their first date in 2009, and it didn’t bode well for their relationship: Rivera claims that Salling, 34, got stoned in his “complete piece of s–t car” and took her to In-N-Out Burger, then to Fright Fest at Six Flags, where he took a slew of pictures with performers at the park … and none with her.

Still, their showmance blossomed into a full-blown relationship. A month later, Rivera says that Salling convinced her to try ecstasy with him.

The couple went on to date for three years, during which Salling told Rivera that his publicist urged him to pretend not to have a girlfriend to preserve his heartthrob image. Rivera agreed to it, but notes, “I had a feeling his pretending to be single had less to do with his publicist and more to do with his d–k.”

Her suspicions were confirmed when her castmates informed her Salling cheated on her. She called her best friend, Madison, and the pair trashed his car with dog food, Coca-Cola, eggs and birdseed … but they didn’t split for good until Salling dumped her a while later. “For a while, there was drama on set, because we hated each other and I didn’t even want him looking at me,” she admitted. “Any time a new person was added to the show, it was like fresh meat being dropped into a piranha tank.”

After her split from Salling, she rebounded with co-star Chord Overstreet briefly, after which she promptly got over Salling and learned her lessons. Still, that doesn’t mean she’d be happy to go through the drama again.

“I think everyone should have that one relationship where you look back and ask yourself, ‘What the hell was I thinking?’ You’ll learn something and you won’t regret it,” she wrote. “Unless, of course, that relationship was with someone who had a sizable stash of child porn on his computer. Then, by all means, regret everything.”

Rivera married actor Ryan Dorsey in 2014. In 2015, they welcomed their now-11-month-old son, Josey.

“Sorry Not Sorry: Dreams, Mistakes and Growing Up” is available Tuesday, Sept. 13.

This article originally appeared in Page Six.