TimeTracking should be independent from whether issuable is saved or not and have its own service
In gitlab-ee!974 I quickly fixed IssuableBaseService
with gitlab-ee@2bfde8998afc7ebfc8ef90f25f8c204d7f4c5c17 so that time tracking could be saved along with the issuable.
The issue is that we couple time tracking with the issuable when there's no need to do so:
- we should track time in
#after_create
(since we need the issuable to be persisted in order to create a time log) &#after_update
- we should delegate time tracking to a service
We could do something like (I think we can do better but don't have the idea right now :)):
def create(issuable)
merge_slash_commands_into_params!(issuable)
filter_params
@time_tracking = TimeTracking.new(issuable, current_user, params.delete(:spend_time))
params.delete(:state_event)
params[:author] ||= current_user
label_ids = process_label_ids(params)
issuable.assign_attributes(params)
before_create(issuable)
if params.present? && create_issuable(issuable, params, label_ids: label_ids)
after_create(issuable)
issuable.create_cross_references!(current_user)
execute_hooks(issuable)
end
issuable
end
def after_create(issuable)
@time_tracking.execute
end