Performance: Cache DB transaction locking of Karma::ActivityLog.add.
This commit is contained in:
parent
e0dc13949a
commit
22a25f266d
1 changed files with 13 additions and 0 deletions
|
@ -20,6 +20,15 @@ add karma activity log of an object
|
||||||
object_id = ObjectLookup.by_name(object)
|
object_id = ObjectLookup.by_name(object)
|
||||||
end
|
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
|
Karma::ActivityLog.transaction do
|
||||||
last_activity = Karma::ActivityLog.where(user_id: user.id).order(id: :desc).lock(true).first
|
last_activity = Karma::ActivityLog.where(user_id: user.id).order(id: :desc).lock(true).first
|
||||||
latest_activity = Karma::ActivityLog.where(
|
latest_activity = Karma::ActivityLog.where(
|
||||||
|
@ -48,6 +57,10 @@ add karma activity log of an object
|
||||||
score: activity.score,
|
score: activity.score,
|
||||||
score_total: local_score_total,
|
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
|
end
|
||||||
|
|
||||||
# set new karma level
|
# set new karma level
|
||||||
|
|
Loading…
Reference in a new issue