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

add remote resource support #2

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

add remote resource support #2

wants to merge 11 commits into from

Conversation

hahn-kev
Copy link
Collaborator

the purpose of this is to investiage how to connect CRDTs and binary files (called resources here) which can't easily be stored as a CRDT directly.

Basically there's RemoteResources, these a tracked in CRDTs and can be referenced by other objects. They contain a reference to a resource on a remote server (auth left up to the app). Then there's a LocalResource, this represents a resource stored locally. There are 3 states a resource can be in.

  • local only
  • remote only
  • remote and local

if the file is local only then the RemoteResource.RemoteId will be null, indicating it has not yet been uploaded.
if DataModel.GetLocalResource returns null that means the resource has not yet been downloaded.

There are 2 apis to help the application list resources that are pending upload or pending download.

There is also an API to help upload resources before a sync.

Base automatically changed from add-crdt to main June 5, 2024 13:35
@hahn-kev hahn-kev force-pushed the remote-resources branch 2 times, most recently from 5f64c2a to 8f29622 Compare June 5, 2024 15:38
Copy link

@jasonleenaylor jasonleenaylor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add anything more to the sample model to demonstrate expected use? Maybe in a follow up?

@hahn-kev
Copy link
Collaborator Author

Yeah that's a good idea. Maybe I'll just make an attached file to the Word entity.

…evant. Update db model snapshot test

add remote resources support.
add method to upload all pending local resources, and call from SyncWithResourceUpload helper method
@hahn-kev hahn-kev requested a review from myieye November 14, 2024 08:54
Copy link
Contributor

@myieye myieye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work here 👍 💪

I just have a few thoughts 💭

src/SIL.Harmony.Tests/ResourceTests/RemoteServiceMock.cs Outdated Show resolved Hide resolved

namespace SIL.Harmony.Tests.ResourceTests;

public class RemoteResourcesTests : DataModelTestBase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your tests you always know before hand if you're dealing with a local or remote resource.

I feel like maybe there should be a public Resource GetResource() method where Resource aggregates the local and remote resource looks something like:

Resource
{
Id,
LocalPath: string?,
RemoteId: string?,
IsLocal: bool,
IsRemote: bool,
}

I suppose a Harmony user could implement it themselves. A join is probably trivial if projected tables are enabled.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that's a good idea

Copy link
Contributor

@myieye myieye Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there was a slight misunderstanding.

You added a GetResources() (plural). My suggestion was for looking up a single resource.
I'm thinking about the case where I have a specific Resource ID, but I don't know if it's local or remote (or both), so I'd like to be able to get a CrdtResource just for that one resource.
a GetResource() would also cover up the fact that local and remote resources are queried differently, which would be a small bonus.

Can we do the join in SQL? I guess it doesn't matter for GetResources() (plural), because everything ends up in memory anyway.

Also I wonder if CrdtResource is a misleading name: the local-resources are explicitly non-crdt values, because they're local only. 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh ok, that makes sense, yeah I can easily make that API (probably on top of the one I just made for now).

As for the name. Yeah that's true, I don't want to use just Resource as the class name as that's way too generic and there's other dotnet classes with the same name so I don't want the confusion. So maybe HarmonyResource?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right Resource is heavily used 😆.
I like HarmonyResource except for the fact that it would be the first type to use the word Harmony in it. 🤔

Some more ideas:

  • UnifiedResource
  • HybridResource

Hybrid sounds coolest, but I think it almost sounds too cool and fancy.
Personally, I think I'd opt for UnifiedResource.

await _crdtRepository.AddLocalResource(localResource);
if (resourceService is not null)
{
var uploadResult = await resourceService.UploadResource(localResource.LocalPath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we roll everything back if the upload fails.
But, the local resource is still valid.
I think it would make more sense to follow the same path we would if resourceService was null. I.e. keep the local resource and add a CreateRemoteResourcePendingUploadChange

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants