With the S&P 500 near record territory, there is a lot of optimism among the investment community. The problem, however, is that some investors might have a hard time finding attractive buying opportunities in this type of market.

Not all businesses are winning for their shareholders, though. In fact, one company in particular, which has a long history of success, has hit a bit of a rough patch.

As of this writing, shares of this restaurant growth stock in particular are down 42% from their July 2021 peak price. Don't be discouraged, though, as you should consider adding it to your portfolio.

Pessimistic in the near term

It hasn't been a happy week for Starbucks (SBUX 1.85%). The ubiquitous coffeehouse chain reported its fiscal 2024 second-quarter financials recently and really disappointed investors.

For the 13-week period ended March 31, Starbucks posted a surprising revenue dip of 2%, which severely missed Wall Street's expectations. This was driven by same-store sales that were down 3% in the U.S. and 11% in China. These are the company's two most important markets, so weakness here is a worrying sign. Starbucks saw a drop in transactions in both countries.

It was even worse on the profitability front. Due to the company's operating expenses remaining flat compared to the year-ago period, coupled with falling revenue, Starbucks posted a 17.2% decline in operating income

"Headwinds discussed last quarter have continued in a number of key markets, we continue to feel the impact of a more cautious consumer, particularly with our more occasional customer, and a deteriorating economic outlook has weighed on customer traffic," CEO Laxman Narasimhan said on the earnings call.

Executives didn't give shareholders much to be excited about, either. They see the struggles continuing, resulting in lowered revenue and earnings guidance for the full fiscal year.

Optimistic about the long term

While it's certainly important to pay attention to fresh quarterly numbers to understand how a business is performing, I always urge investors to focus their attention on the next few years, as opposed to the next few weeks or months. A long-term mindset helps an investor focus on what really matters.

There are reasons to remain optimistic about Starbucks. Its powerful brand is one of them. There are not many companies that resonate with consumers quite like this one, a standing built up over many decades thanks to consistently delivering for customers. The brand is Starbucks' key competitive advantage, and it has helped drive pricing power.

Bolstering that brand is Starbucks' intense focus on investing in its digital capabilities. Despite a poor showing last quarter, the company was still able to grow its loyalty membership 6% in the U.S. Starbucks' mobile app increases accessibility and convenience for customers while providing the business with a valuable marketing channel.

There is still a ton of growth potential too, according to the leadership team. By 2030, the goal is for Starbucks to have 55,000 stores open worldwide, up from the current count of 38,951. Management believes the biggest opportunities lie in the U.S. and China.

And thanks to the stock's recent weakness, the valuation is cheap. Shares trade at a price-to-earnings ratio of 20. That's about the lowest multiple they have sold for in the past two years.

Investing is best when it's viewed as a long-term game. Chances are high that Starbucks will eventually get back on a stronger footing, especially in its biggest two markets, making this is a beaten-down stock you should consider buying today.