Skip to content

Commit

Permalink
[ENG-1548] use in-memory instances when sending messages to cloud (#2057
Browse files Browse the repository at this point in the history
)

* use in-memory instances when sending messages to cloud

* comments
  • Loading branch information
Brendonovich committed Feb 6, 2024
1 parent 2d0c340 commit bb0d0af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
9 changes: 1 addition & 8 deletions core/src/cloud/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,7 @@ pub async fn declare_actors(library: &Arc<Library>, node: &Arc<Node>) {
let library = library.clone();
let node = node.clone();

move || {
send::run_actor(
library.db.clone(),
library.id,
library.sync.clone(),
node.clone(),
)
}
move || send::run_actor(library.id, library.sync.clone(), node.clone())
},
autorun,
)
Expand Down
24 changes: 11 additions & 13 deletions core/src/cloud/sync/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use super::CompressedCRDTOperations;

use sd_cloud_api::RequestConfigProvider;
use sd_core_sync::{GetOpsArgs, SyncMessage, NTP64};
use sd_prisma::prisma::{instance, PrismaClient};
use sd_utils::from_bytes_to_uuid;
use uuid::Uuid;

use std::{sync::Arc, time::Duration};
Expand All @@ -13,24 +11,22 @@ use tokio::time::sleep;
use super::err_break;

pub async fn run_actor(
db: Arc<PrismaClient>,
library_id: Uuid,
sync: Arc<sd_core_sync::Manager>,
cloud_api_config_provider: Arc<impl RequestConfigProvider>,
) {
loop {
loop {
let instances = err_break!(
db.instance()
.find_many(vec![])
.select(instance::select!({ pub_id }))
.exec()
.await
)
.into_iter()
.map(|i| from_bytes_to_uuid(&i.pub_id))
.collect::<Vec<_>>();
// all available instances will have a default timestamp from create_instance
let instances = sync
.timestamps
.read()
.await
.keys()
.cloned()
.collect::<Vec<_>>();

// obtains a lock on the timestamp collections for the instances we have
let req_adds = err_break!(
sd_cloud_api::library::message_collections::request_add(
cloud_api_config_provider.get_request_config().await,
Expand All @@ -44,6 +40,7 @@ pub async fn run_actor(

use sd_cloud_api::library::message_collections::do_add;

// gets new operations for each instance to send to cloud
for req_add in req_adds {
let ops = err_break!(
sync.get_ops(GetOpsArgs {
Expand Down Expand Up @@ -83,6 +80,7 @@ pub async fn run_actor(
break;
}

// uses lock we acquired earlier to send the operations to the cloud
err_break!(
do_add(
cloud_api_config_provider.get_request_config().await,
Expand Down

0 comments on commit bb0d0af

Please sign in to comment.