-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Conversation
5f64c2a
to
8f29622
Compare
There was a problem hiding this 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?
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
e7b004c
to
034c3dc
Compare
# Conflicts: # src/SIL.Harmony/DataModel.cs # src/SIL.Harmony/Db/CrdtRepository.cs
There was a problem hiding this 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 💭
|
||
namespace SIL.Harmony.Tests.ResourceTests; | ||
|
||
public class RemoteResourcesTests : DataModelTestBase |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. 🤔
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
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.
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.