❔ How would you write this service better?

The service:
13 Replies
phaseshift
phaseshift2y ago
for starters I wouldnt return null to something expecting a list
antimatter8189
can you point me to the method where? where am i returning null? 😮
phaseshift
phaseshift2y ago
GetUserLessons
antimatter8189
oh yeah thats a mistake for sure , thx. see anything else?
phaseshift
phaseshift2y ago
Why do you have a repository and cache a list of lessons?
antimatter8189
Yeah thats what i was wondering about, whats the best practice for this?
phaseshift
phaseshift2y ago
don't have two things for the same state
antimatter8189
I mean if i load all user related lessons i can just place them in a private field and work on them no? what do you mean? repo only performs db operations it doesnt save an in app state
phaseshift
phaseshift2y ago
db is for saving state. wdym
antimatter8189
Yeah but if if i dont want to make a db call each time smth happens on the ui I can work on the fields and only save to db when needed no?. or its the wrong way Like for example a user went into a lesson and didnt start it, why would i load it from the db? no changes happened Or if he gave no answers so why read a non changed entity from the db ?
phaseshift
phaseshift2y ago
SetActiveLesson - that's just setting some kind of ui state, but yet its making repo calls as well It's not clear what is transient/ui data and what is permanent/repo data
pox
pox2y ago
db reads are not that expensive, normally you want to avoid using a cache
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.