Jump to content

returning value whilst updating db


RuleBritannia

Recommended Posts

Hello

 

So I must return a value from somewhere, lets say image total uploaded count from a user account check.

The value is returned, used within a loop etc.

I also want to update my database with that figure, and a timestamp when it was checked.

 

I know I can put this inside one function, so that after the value check, I can update a table and so on, But this breaks the single responsibility principle, as my function will be doing multiple things.

 

Im curios how you would do this sticking to SOLID principles whilst not making a complete mockery at the same time.

 

Thanks in advance.

Link to comment
Share on other sites

Use two functions?

 

But, really, I think this can be achieved in a better way without needing to store the data from the query. You state you want to save the number of images associated with a user and the timestamp of when it was checked. But, if you are storing the uploaded images as individual records in a separate table with timestamps of when they were uploaded, then you can run a query at any time to know what the counts were at any point in time in the past or currently. So, running these queries to get the results and then store that data seems to be counterproductive.

Link to comment
Share on other sites

Use two functions?

 

But, really, I think this can be achieved in a better way without needing to store the data from the query. You state you want to save the number of images associated with a user and the timestamp of when it was checked. But, if you are storing the uploaded images as individual records in a separate table with timestamps of when they were uploaded, then you can run a query at any time to know what the counts were at any point in time in the past or currently. So, running these queries to get the results and then store that data seems to be counterproductive.

 

The images are not on my server, Lets say for exmaple imageshack.us, I login, check total images, logout.

Link to comment
Share on other sites

The images are not on my server, Lets say for exmaple imageshack.us, I login, check total images, logout.

 

OK, gotcha. I'd probably build a function that gets the list of images. Then call a 2nd function to update the requisite data. But, if you are getting the information from a 3rd party site you probably need some processes to connect to that site and some other things. So, maybe creating a class with all the relevant methods would be a better plan.

Link to comment
Share on other sites

OK, gotcha. I'd probably build a function that gets the list of images. Then call a 2nd function to update the requisite data. But, if you are getting the information from a 3rd party site you probably need some processes to connect to that site and some other things. So, maybe creating a class with all the relevant methods would be a better plan.

Yes I do have a class specifically for fetching the data from the imagehost, But according to SOLID principles, I should be making a second class for database actions, But within the code this seems illogical when it could be handled within 1 class.

Link to comment
Share on other sites

Right, . . . but at some point following such principles, rules, whatever can actually become counter-productive. If you are working on a large product with many different developers involved then following strict processes is important to prevent problems and make everyone more efficient. But, if you are working on a small, personal project you can dispense with getting too granular. If you have a process that does three things, those three things will always be done the same way, they are relatively 'small', and those three things will never be done independently - it can be easier to build them together.

Link to comment
Share on other sites

Right, . . . but at some point following such principles, rules, whatever can actually become counter-productive. If you are working on a large product with many different developers involved then following strict processes is important to prevent problems and make everyone more efficient. But, if you are working on a small, personal project you can dispense with getting too granular. If you have a process that does three things, those three things will always be done the same way, they are relatively 'small', and those three things will never be done independently - it can be easier to build them together. That's my two cents.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.