diff --git a/app/models/karma/activity_log.rb b/app/models/karma/activity_log.rb index 38263899b..a3aacbc73 100644 --- a/app/models/karma/activity_log.rb +++ b/app/models/karma/activity_log.rb @@ -20,6 +20,15 @@ add karma activity log of an object object_id = ObjectLookup.by_name(object) end + # scheduler transactions causes a lot of calls + # so we try to cache the add process + # to skip the time loss of the transaction + # to increase performance + if !force + cache = Cache.get("Karma::ActivityLog.add::#{activity.once_ttl.seconds}::#{action}::#{user.id}::#{object}::#{o_id}") + return cache if cache + end + Karma::ActivityLog.transaction do last_activity = Karma::ActivityLog.where(user_id: user.id).order(id: :desc).lock(true).first latest_activity = Karma::ActivityLog.where( @@ -48,6 +57,10 @@ add karma activity log of an object score: activity.score, score_total: local_score_total, ) + + if !force + Cache.write("Karma::ActivityLog.add::#{activity.once_ttl.seconds}::#{action}::#{user.id}::#{object}::#{o_id}", true, expires_in: activity.once_ttl.seconds) + end end # set new karma level