Hi All,
I would like to know more about what is the best way to write the view and query for get the results using single view and query.
Let me explain my user story here, How i am doing currently.
DataBase Name : KMM Collage.
Roles:Manager,Admin,Principle,HOD,Lecture.
userRole : Manager = 0, Admin = 0,Principle = 0,HOD = 1, Lecture = 2.
Document Information:
{
id : hjd565673fjd847567465,
student : "Prasanna Kumar",
department : "Lecture/HOD"
marks:{
1:"hhfdh"
2:"jfjf"
}
type :"KMM.Type"
}
Filter Pull Replication
> I have filter replication according to login role we have to filter the documents.
> If login user is HOD, i have to filter only his documents.
> else if login user is Lecture, i have to filter only his documents
> else if login user is (Manager,Admin,Principle), i have to filter all documents
Now Pull replication is done according there roles.
Note: The user may switch at any time, if may documents are not available than we have to pull(according his all ).
Views and Queries
com.couchbase.lite.View viewTicketsPerProjectPagination = database.getView(String.format("%s/%s", D_DOCNAME, TICKETS_PER_PROJECT_PAGINATION));
viewTicketsPerProjectPagination.setMap(new Mapper() {
@Override
public void map(Map<String, Object> document, Emitter emitter) {
if (DOCTYPE_TICKET.equals(document.get(TYPE))) {
emitter.emit(new Object[]{userRole == 0?document.get(TYPE):document.get("department")}, null); }
}
}, "1." + userRole);
Query Part:
com.couchbase.lite.View viewPerGetAllTickets = AppConstants.database.getView(String.format("%s/%s", D_DOCNAME,TICKETS_PER_PROJECT_PAGINATION);
queryForGetTickets = viewPerGetAllTickets.createQuery().toLiveQuery();
queryForGetTickets.setStartKey(new Object[]{userRole == 0?"KMM.Type": Lecture});queryForGetTickets.setEndKey(new Object[]{userRole == 0?"KMM.Type": Lecture});queryForGetTickets.run();
Note : The index will be change according user role.
Questions :
1) Is this best way to do the thinks, like making reindex views again and again when user role is changed.
2) Between if i gonna write multiple views and query there is big problem like performance wise.
3) Even though if i do like point number 1, there is also performance issue will i thinks(when it is bigger database)
4) How i can do the best out of the above user story. Irrespective of the Performance and reducing the un wanted views
Note : Reindexing view in multiple times, is that good idea for large databases
Please help me out how i can solve this problem, thanks in advance.
if any clarification or any information please revert me back.
Thank You,
P Prasanna Kumar.