Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend:kv query changes with options #726

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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