From 4918932a0ec32178fbaebf35f943a8030d72b56a Mon Sep 17 00:00:00 2001 From: LDA Date: Sat, 17 Aug 2024 01:08:09 +0200 Subject: [PATCH] [MOD/WIP] Separate DB entries for the txns --- src/User.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/User.c b/src/User.c index 5d7f50f..8e12773 100644 --- a/src/User.c +++ b/src/User.c @@ -977,39 +977,57 @@ HashMap * UserGetTransaction(User *user, char *transaction, char *path) { HashMap *devices; + DbRef *ref; if (!user || !transaction || !path) { return NULL; } - devices = JsonValueAsObject( - HashMapGet(UserGetDevices(user), UserGetDeviceId(user)) + ref = DbLock(user->db, + 4, + "users", user->name, + "txns", UserGetDeviceId(user) ); - return JsonDuplicate(JsonValueAsObject( - JsonGet(devices, 3, "transactions", path, transaction) - )); + devices = DbJson(ref); + devices = JsonValueAsObject(JsonGet(devices, 2, path, transaction)); + devices = JsonDuplicate(devices); + DbUnlock(user->db, ref); + return devices; } void UserSetTransaction(User *user, char *transaction, char *path, HashMap *resp) { HashMap *devices; + DbRef *ref; if (!user || !transaction || !path || !resp) { return; } - devices = JsonValueAsObject( - HashMapGet(UserGetDevices(user), UserGetDeviceId(user)) - ); + if (!(ref = DbLock(user->db, + 4, + "users", user->name, + "txns", UserGetDeviceId(user) + ))) + { + ref = DbCreate(user->db, + 4, + "users", user->name, + "txns", UserGetDeviceId(user) + ); + } + devices = DbJson(ref); /* Overwrite the transaction */ JsonValueFree(JsonSet( devices, JsonValueObject(JsonDuplicate(resp)), - 3, "transactions", path, transaction + 2, path, transaction )); + + DbUnlock(user->db, ref); } void UserAddInvite(User *user, char *roomId)