Skip to content

Commit

Permalink
backend:kv query changes with options (#726)
Browse files Browse the repository at this point in the history
Co-authored-by: arjuna92 <128050696+arjuna92@users.noreply.github.com>
  • Loading branch information
vijaygupta18 and arjuna92 authored Dec 19, 2024
1 parent 9cfefb7 commit bed1c73
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 4 deletions.
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 71 additions & 1 deletion lib/mobility-core/src/Kernel/Beam/Functions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ module Kernel.Beam.Functions
findOneWithKVRedis,
logQueryData,
findAllFromKvRedis,
createWithKVWithOptions,
createWithKVSchedulerWithOptions,
updateWithKVWithOptions,
updateWithKVSchedulerWithOptions,
updateOneWithKVWithOptions,
)
where

Expand Down Expand Up @@ -102,7 +107,8 @@ meshConfig =
kvHardKilled = True,
cerealEnabled = False,
tableShardModRange = (0, 128),
redisKeyPrefix = ""
redisKeyPrefix = "",
forceDrainToDB = False
}

runInReplica :: (L.MonadFlow m, Log m) => m a -> m a
Expand Down Expand Up @@ -415,6 +421,18 @@ updateWithKV ::
updateWithKV setClause whereClause = withUpdatedMeshConfig (Proxy @table) $ \updatedMeshConfig -> do
updateInternal updatedMeshConfig setClause whereClause

updateWithKVWithOptions ::
forall table m r.
(BeamTableFlow table m, EsqDBFlow m r) =>
Maybe Integer ->
Bool ->
[Set Postgres table] ->
Where Postgres table ->
m ()
updateWithKVWithOptions ttl forceDrain setClause whereClause = withUpdatedMeshConfig (Proxy @table) $ \updatedMeshConfig -> do
let updatedMeshConfig' = updatedMeshConfig {redisTtl = fromMaybe (redisTtl updatedMeshConfig) ttl, forceDrainToDB = forceDrain}
updateInternal updatedMeshConfig' setClause whereClause

updateWithKVScheduler ::
forall table m r.
(BeamTableFlow table m, EsqDBFlow m r) =>
Expand All @@ -424,6 +442,18 @@ updateWithKVScheduler ::
updateWithKVScheduler setClause whereClause = withUpdatedMeshConfig (Proxy @table) $ \updatedMeshConfig -> do
updateInternal updatedMeshConfig setClause whereClause

updateWithKVSchedulerWithOptions ::
forall table m r.
(BeamTableFlow table m, EsqDBFlow m r) =>
Maybe Integer ->
Bool ->
[Set Postgres table] ->
Where Postgres table ->
m ()
updateWithKVSchedulerWithOptions ttl forceDrain setClause whereClause = withUpdatedMeshConfig (Proxy @table) $ \updatedMeshConfig -> do
let updatedMeshConfig' = updatedMeshConfig {redisTtl = fromMaybe (redisTtl updatedMeshConfig) ttl, forceDrainToDB = forceDrain}
updateInternal updatedMeshConfig' setClause whereClause

-- updateOne --

updateOneWithKV ::
Expand All @@ -435,6 +465,18 @@ updateOneWithKV ::
updateOneWithKV setClause whereClause = withUpdatedMeshConfig (Proxy @table) $ \updatedMeshConfig -> do
updateOneInternal updatedMeshConfig setClause whereClause

updateOneWithKVWithOptions ::
forall table m r.
(BeamTableFlow table m, EsqDBFlow m r) =>
Maybe Integer ->
Bool ->
[Set Postgres table] ->
Where Postgres table ->
m ()
updateOneWithKVWithOptions ttl forceDrain setClause whereClause = withUpdatedMeshConfig (Proxy @table) $ \updatedMeshConfig -> do
let updatedMeshConfig' = updatedMeshConfig {redisTtl = fromMaybe (redisTtl updatedMeshConfig) ttl, forceDrainToDB = forceDrain}
updateOneInternal updatedMeshConfig' setClause whereClause

-- create --

createWithKV ::
Expand All @@ -448,6 +490,20 @@ createWithKV ::
createWithKV a = withUpdatedMeshConfig (Proxy @table) $ \updatedMeshConfig -> do
createInternal updatedMeshConfig toTType' a

createWithKVWithOptions ::
forall table m r a.
( BeamTableFlow table m,
EsqDBFlow m r,
ToTType' (table Identity) a
) =>
Maybe Integer ->
Bool ->
a ->
m ()
createWithKVWithOptions ttl forceDrain a = withUpdatedMeshConfig (Proxy @table) $ \updatedMeshConfig -> do
let updatedMeshConfig' = updatedMeshConfig {redisTtl = fromMaybe (redisTtl updatedMeshConfig) ttl, forceDrainToDB = forceDrain}
createInternal updatedMeshConfig' toTType' a

createWithKVScheduler ::
forall table m r a.
( BeamTableFlow table m,
Expand All @@ -459,6 +515,20 @@ createWithKVScheduler ::
createWithKVScheduler a = withUpdatedMeshConfig (Proxy @table) $ \updatedMeshConfig -> do
createInternal updatedMeshConfig toTType'' a

createWithKVSchedulerWithOptions ::
forall table m r a.
( BeamTableFlow table m,
EsqDBFlow m r,
ToTType'' (table Identity) a
) =>
Maybe Integer ->
Bool ->
a ->
m ()
createWithKVSchedulerWithOptions ttl forceDrain a = withUpdatedMeshConfig (Proxy @table) $ \updatedMeshConfig -> do
let updatedMeshConfig' = updatedMeshConfig {redisTtl = fromMaybe (redisTtl updatedMeshConfig) ttl, forceDrainToDB = forceDrain}
createInternal updatedMeshConfig' toTType'' a

-- delete --

deleteWithKV ::
Expand Down

0 comments on commit bed1c73

Please sign in to comment.