I am newbie to contentful and I have written an android application which uses content delivery API to fetch the content from my space.
I have used Vault and normal API (without vault) to fetch the content.
I observe that there is always a 3-5 seconds of delay in fetching the delta changes (new and update content).
My requirement is to give a real time data sync.
Is this an issue with my implementation or its an expected behaviour from contentful.
Sample code: 1. Using Vault
Vault.with(App.getInstance(), SampleSpace.class).requestSync(
SyncConfig.builder()
.setClient(ClientProvider.get())
.setInvalidate(false)
.build());
List<SampleTable> appointments = Vault.with(App.getInstance(), SampleSpace.class)
.fetch(SampleTable.class)
.where(SampleTable$Fields.DATE+"=?", mDateToCheck)
.all();
Normal API
private final CDAClient client = CDAClient.builder().setToken(CDA_TOKEN).setSpace(SPACE_ID).build();
client.observe(CDAEntry.class).all()
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(new Action1<CDAArray>() {
@Override
public void call(CDAArray entries) {
//business logic here
}});
Thanks for your time and help!!
I'm a maintainer of the Java and Android SDKs in Contentful.
There could be some reasons for the slowdown:
1) You are syncing
a lot of data
This would mean, that a lot of data, potentially even different pages have to be fetched from Contentful, parsed, serialised and put into the database in the Vault case.
In this case taking a look at fetching the entries by id and not using sync might be an idea. Sadly you would loose the niceness of Vault model classes and would need to implement the mapping from Contentful models to your custom models yourself.
2) ClassLoader.getResources
In your code snippet, you are recreating a CDAClient
or Vault
with every sync call. This has a known issue on Android and we are currently working on fixing it.
For now, till an update is out, the recommendation is to try and see if storing Vault
and/or the CDAClient
in a field might be helpful for subsequent calls.
3) The network is slow
Sadly this would mean, there is nothing we can do from our side ... ;)
I hope this gives you some pointers, on a solution, please feel free to report back with any progress you encounter.