Is there a consensus on how long you should know a person before you ask him/ her to write you a recommendation letter for graduate school?
What I personally have done is that if I get an A+/A/A- with his course I would reach out to him for a recommendation letter. This might not be the case for several Professors (it is a case by case basis), but in general this works. I also would ask for recommendations for Professor's that I have done research projects with.