Meteor-Community-Packages / Meteor-Community-Packages/ground-db
Ground DB v2 suddenly empty
- Dominant language
- JavaScript
- Stars
- 569
- Forks
- 77
- PR merge metrics
- No merged PRs in 30d
Description
Hi @raix ,
I am having a big problem with ground db. First, I used the atmosphere version (0.3.15?), now I updated to
ground:db 2.0.0-rc.6, hoping this would fix my problem.
I am using Meteor React and this is the code for the main container, which is supposed to block other pages from loading before the offline database has been populated (later I will add a check if the Ground DB has already been loaded at an earlier session)
let fullyLoaded = new ReactiveVar(false);
let subscribed = false;
let subscribedOnce = false;
let checking = false;
export default createContainer(() => {
if(Meteor.status().connected && !subscribedOnce && !subscribed){
subscribed = true;
console.log("subscribing");
Meteor.subscribe("localization",
()=> {
localizationGrounded.keep(Localization.findNonGrounded());
console.log("everything has been loaded once.");
console.log("Localization count after subscription: " + Localization.find().fetch().length);
fullyLoaded.set(true);
subscribed = false;
subscribedOnce = true;
}
);
}
if(fullyLoaded.get()){
console.log("Localization Count: " + Localization.find().fetch().length)
}
return {
isLoggedIn: !!Meteor.userId(),
isLoading: !fullyLoaded.get() || subscribed,
};
}, Main);
This code is supposed to subscribe to "localization" if it hasn't been loaded already. The Localization Collection is implemented as follows, the find() and findOne() method has been overwritten to call find() for the grounded DB:
export const Localization = new Mongo.Collection('localization');
if(Meteor.isClient){
export let localizationGrounded = new Ground.Collection('localization', {
cleanupLocalData: false
});
//rename find() to findNonGrounded
Localization.findNonGrounded = Localization.find;
localizationGrounded.observeSource(Localization.findNonGrounded());
Localization.find = function(...args){
console.log("finding from ground db");
return localizationGrounded.find(...args);
};
Localization.findOne = function(...args){
console.log("finding one from ground db");
return localizationGrounded.findOne(...args);
}
}
This however produces the following output:
subscribing
everything has been loaded once
finding from ground db
Localization count after subscription: 28
finding from ground db
Localization count: 28
Looks fine, right? Unfortunately, the createContainer() function is called once more immediately after that, resulting in
...
Localization count: 28
//Lots of "finding one from ground db" indicating the page is being localized correctly
finding from ground db
Localization Count: 0
//more "finding one from ground db", this time returning undefined
which as I understand it means, the Ground DB was emptied without me doing it.
Please help me to fix this.
Thanks in advance
Contributor guide
Research direction
Start by reproducing the issue from the shown Meteor React createContainer entry point, including the localization subscription and Ground.Collection observeSource setup. Compare the collection state after the subscription callback with the next container invocation; done means Localization.find() and findOne() continue returning the populated records without an unexplained reset.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100