Issue
I am working on an Ionic app with PouchDB that needs to sync tables with remote CouchDB server. In the constructor of my database.ts provider I have 6 methods:
this.initialiseDB_Ord();
this.initialiseDB_IngProd();
this.initialiseDB_Ing();
this.initialiseDB_Prod();
this.initialiseDB_OrdProd();
this.initialiseDB_Ut();
Each of these methods does the following (I pick the first one as example):
this._DB_Ord = new PouchDB('orders');
this._remoteDB_Ord = this.addressIP + '/orders';
this._syncOpts_Ord = { live : true,
retry : true,
continuous : true};
this._DB_Ord.sync(this._remoteDB_Ord, this._syncOpts_Ord)
.on('change',(info) => {
console.log('Handling syncing change');
console.dir(info);
}).on('paused',(info)=> {
console.log('Handling syncing pause');
console.dir(info);
}).on('active', (info) => {
console.log('Handling syncing resumption');
console.dir(info);
}).on('denied', (err) =>{
console.log('Handling syncing denied');
console.dir(err);
}).on('complete', (info) =>{
console.log('Handling syncing complete');
console.dir(info);
}).on('error', (err)=>{
console.log('Handling syncing error');
console.dir(err);
});
then I have a handleSyncing method as follows:
handleSyncingUt() {
this._DB_Ut.changes({
since : 'now',
live : true,
include_docs : true,
attachments : true
})
.on('change', (change) =>
{
console.log('Handling change');
console.dir(change);
})
.on('complete', (info) =>
{
console.log('Changes complete');
console.dir(info);
})
.on('error', (err) =>
{
console.log('Changes error');
console.log(err);
});
}
If I have at maximum 5 Databases it works fine. When the sixth DB is added it doesn't synchronize local pouchDB and remote couchDB in real time but only when the app is first opened.
Can someone help me?
Solution
@lossleader is right on the money about the max number of connections in a browser/WebView. At Quizster, we have this same problem as Quizster has to sync as many as 10 PouchDB instances simultaneously. This is done using Howler to subscribe to changes for a set of databases. Upon a change to one of these databases, Quizster issues a one-time (not live) sync between the PouchDB instance and the CouchDB cluster.
For a little more background: Quizster has to sync this many PouchDB instances as:
- Doing this avoids having to replicate even more data between databases, which leads to lower latency with shared data
- Quizster uses a lot of database views to speed up replication and keep the size of the data sets small. And, each view effectively leads to its own PouchDB instance.
I'm planning on open sourcing more of the Quizster stack soon and hope to release some tutorials as well.
Answered By - redgeoff
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.