[ENG-1548] use in-memory instances when sending messages to cloud (#2057)

* use in-memory instances when sending messages to cloud

* comments
This commit is contained in:
Brendan Allan 2024-02-06 17:13:47 +08:00 committed by GitHub
parent 2d0c340e58
commit bb0d0af6a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 21 deletions

View file

@ -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,
)

View file

@ -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};
@ -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,
@ -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 {
@ -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,