I have created a stored procedure GetNotifications that returns all notifications for a specific user. Other developers are using this SP at many different places.
Now we have a need to implement a paging functionality so that we do not flood users with all notifications at the same time.
I cannot modify the existing SP since it’s being used.
I can create another SP with paging functionality in it but I really don’t want to do that since it requires a lot of repeating code and of course it would suck if we change the business logic for getting notifications in future.
This is something I can do: create a new SP that internally calls the GetNotifications and then implement the paging on the returned result-set. But then wouldn’t it be unnecessary load on the server since the GetNotifications will return all the results regardless?
Can you think of a better way to approach this problem?
Modify the stored procedure with an optional parameter to return either the paged functionality, or all results (the default). This should give you the functionality you need without breaking existing code.