My personal rule is to have one or two pieces that I’m working on polishing, and everything else that I’m just getting to ‘Good enough’ before moving on. I’m generally working on the polishing piece for at least a month or two, for tunes that last about 1 minute per repeat. I find benefits from both polishing and moving on quickly. And when I’m done polishing, the song isn’t perfect. I may still have a note that I flub some of the time, or a phrase where I’ve worked out an easier variation to the original. It’s just better than it would be without the polish, and at a point where I feel like more time spent will get me very little improvement.
By learning a new piece quickly, I get the benefit of picking up new skills and techniques, and learning where to apply them, and if I don’t like something, I don’t have to keep playing it. But it takes a lot longer to master things. By focusing on a piece for months, I make the skills used in that piece really, really solid. I can then apply them to other pieces, including when I’m coming up with variations on the fly. These pieces also become a base that I can use when new techniques come up, and I want to apply a new skill. By choosing a song or tune I can play without much thought, I can think about the new skill, or the new variation, rather than concentrating on the basic tune. They also make tunes that I can lead when I’m playing with a group.
Just starting out, it can be hard to recognize when it’s time to move on. As a rule of thumb, if you’re frustrated by a piece that you’ve mostly learned, its time to move on. The last few mistakes are probably due to an overall lack of skill, and you’ll fix them without even trying as you learn more music. You’ll get more benefit from moving on to the next piece, and coming back to the troublesome one in a month or two. A teacher is great for helping with this.
I didn’t address improvisation in this answer because I don’t think it makes a difference in whether you should focus on a song or move on quickly. Improvising around songs you know backwards, forwards, and upside down is a whole lot easier than trying to fit an improvisation around something you don’t really know at all. So to start with, use the pieces you decide to polish as a base for learning improvisation.
To summarize: If you’ve got only 1-2 minor mistakes, its time to move on. Revisit the pieces later, to check your progress. Don't try to polish anything until you run into a song you like well enough to play for a month or two.