android - Fetching Single Item From Realm DB where the item is the Item with most recent timestamp -
i using realm db
in android app , want fetch 1 item recent timestamp. couldn't achieve because don't know do. but, i'm doing
topicmodel topicmodel = realm.where(topicmodel.class).equalto("rootmessageid", getrootmessageid()).findfirst(); list<messagemodel> messagemodel = realm.where(messagemodel.class) .equalto("themaintopidid", topicmodel.getradomudid()) .findallsorted("updatedtime", sort.descending); log.e(tag, "recent message: " + messagemodel.get(messagemodel.size() - 1).getupdatedtime());
i don't think can same implementation describe mongodb. sorting results @ end of or after query.
however, realmresults after calling findall example very low memory consuming list of references. results query not copied objects, references. see class description of realmresults:
this class holds matches of realmquery given realm. objects not copied realm realmresults list, referenced realmresult instead. saves memory , increases speed.
so shouldn't matter. , if want find recent message, one-liner instead:
messagemodel mm = realm.where(messagemodel.class) .equalto("themaintopidid", topicmodel.getradomudid()) .findallsorted("updatedtime", sort.descending) .where() .findfirst();
Comments
Post a Comment