Monday, January 25, 2016

Reading Parse.com docs

I got less time to do my things today. Most of the day went by playing with my son as maid took leave today.
Most part of the remaining time i read parse docs. Learnt a lots of new things about parse and also got some ideas out of it for my app.
When i turned on my system to work I managed to get the comment thing sorted out.
Actually i never mentioned it before here. So here it goes.
In MySQL i was using id for the content that were integers and they were getting incremented automatically on every new row added. I was using this id in the comments table to label which content this comment belongs to. Easy stuff that is.
But here in parse they use NoSQL database that doesn't give auto incrementing integers as id rather they give a alphanumeric objectId. So if i add a new row to content it will not generate same type of integer id so i will have to use objectId in comment table to link comments to newer content.
Now the problem arises how to write the query because old content will not have new objectId in comments and new on will not have the old content id.
To sort this out i needed to add objectId of the content to all the respective comments. I couldn't do it manually because there were 22,000 comments in all.
I needed an automated approach.
I had two options:
1. I use the cloud code facility that parse provide. To use it i needed to write a JavaScript function and run it on the data.
2. I extend my existing android code and update the ids using the app.
First option was little difficult for me as i have never done any of that stuff before. I mean i never used parse cloud code or the tools required to write cloud code. And also i never wrote such a JavaScript function before. But it could have been a nice learning experience.
I chose second option because it required very less time in comparison to first one and also i could track the changes i was introducing with android logcat, so i would not corrupt the data. Although i backed up all data before hand.
I wrote a java method that pulled all the comments attached to old content id and then update each of them by inserting new content objectId in it. I could have done it to all the data at once but i chose to go with one at a time approach. I tapped on the content and all the comment rows related to that content got updated and i tracked it in the parse interface and logcat window.
Took time but finally managed to update all.
Finally i updated the query to use the objectId rather than old content id in the android app to pull the comments. Working nicely.
Yesterday i updated the android app to send objectId for new comments so nothing was required to change in that method. 
Reading through the parse documents i learnt about the caching the data in device so i won't have to query it every time i needed more data. Nice function. Would use it. It will make things faster. Tomorrow will try to implement this caching thing.
One thing that went unexpectedly nice as i switched to parse is that when i was using JSON to get and sent data to and from app i was not getting the emoji working. They were changing into question marks. But now i can use all the emoji in content as well as in comments 🙌.
Later.

No comments:

Post a Comment