People, especially those who do not have a close relationship with you, do not care how hard you worked on something. Case in point, I remember situations when someone tried to rush through demonstrating a minimal effort piece of work and got stopped, asked many questions, and figuratively padded on the back multiple times to their astonishment. Why did they get praise for trivialities?
If you are a bit more seasoned, you might know the answer already. Only the impact on the audience matters and drives its interest and appreciation more than heroic late nights and technical brilliance. You should not expect much enthusiasm from others if the impact is
Internal to your team mostly
Removing technical debt
Strategic long-term beyond quarterly horizons
Adding security or removing risk
These have no immediate, measurable ROI or grateful audience, or their absence is more impactful than their presence, e.g. security and risk management.
Other examples are where the effort greatly outweighed the impact, but it needed doing for good or bad reasons. Good reasons can be foundational work, and the first value drop is minimal, and the impact is strategic, enabling future work and value delivery. Bad reasons can be poor planning or non-data-driven decision-making, e.g. based on gut feeling or tradition or because everyone else is doing it.
Once you understand the above, you can use it to your and your organisation's advantage. Break with the expectation that people appreciate your effort and become comfortable with celebrating value delivery. Sometimes you put in a lot of work for little immediate value, but it pays back later when you occasionally get a lot of value for little effort. It should average over time, and hopefully, overall, you get the appreciation you deserve. But it takes a little learning and attention to 'sell' your work according to its value. I advise juniors to promote and savour the easy wins, get the attention and appreciation, and not dwell on the unappreciated low-impact hard wins.
There is another significant benefit attached to working this way. It starts pivoting your view. I used to look at the world through the eyes of an engineer at the beginning of my career. Every problem had an elegant technical solution, and complex problems were more interesting than simple ones. That is divorced from what happens in reality. No one outside the team building the solution cares about its implementation or sophistication.
Businesses care about impact, e.g. is something possible and feasible in resources and time? Quickly you learn that sometimes good is good enough or some problems are not worth solving no matter how irresistible they are. For a data scientist, it can mean using a simple, robust, boring algorithm instead of the latest complex ones or developing your own. For engineers, it can mean using existing tools, libraries or services instead of building your own.
If enough individuals in a business realise this, good things happen. It achieves valuable outcomes faster and more effectively. Poorly motivated goals may still exist, but they might be starved of resources or achieved with absolutely minimal effort since there is no or little value in them. Importantly, you will save your hard work for worthwhile goals, which spares you disappointment and the business wastage. Businesses either learn and reduce poorly motivated goals or lose their best staff in the long term.
Looking at how your work is perceived and how it adds or does not add value to your organisation can help you avoid disappointment. And it can make you better at your job by avoiding some unappreciated work that is unnecessary. But there will always be necessary thankless work. Luckily there will be easy wins where you change one line of code and have people cheering you because it made their (work) lives better.