Skip to content

Commit d10fc02

Browse files
mayank8318iamareebjamal
authored andcommitted
fix: Use threaded asynchronous transaction using separate Realm instance. (fossasia#2324)
1 parent 41ab3a7 commit d10fc02

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

android/app/src/main/java/org/fossasia/openevent/data/repository/RealmDataRepository.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,7 @@ public User getUserSync() {
123123

124124
public void clearUserData() {
125125
Realm realm = Realm.getDefaultInstance();
126-
realm.executeTransaction(new Realm.Transaction() {
127-
@Override
128-
public void execute(Realm realm) {
129-
realm.delete(User.class);
130-
}
131-
});
126+
realm.executeTransaction(realm1 -> realm1.delete(User.class));
132127
realm.close();
133128
}
134129

@@ -555,14 +550,15 @@ public RealmResults<SessionType> getSessionTypesSync() {
555550

556551
/**
557552
* Saves Event Dates Synchronously
558-
* TODO : Use threaded asynchronous transaction using separate Realm instance
559553
* @param eventDates List of dates of entire event span (inclusive)
560554
*/
561555
private void saveEventDatesInRealm(List<EventDates> eventDates) {
562-
realm.beginTransaction();
563-
realm.delete(EventDates.class);
564-
realm.insert(eventDates);
565-
realm.commitTransaction();
556+
Realm realm = Realm.getDefaultInstance();
557+
realm.executeTransaction(transaction -> {
558+
transaction.delete(EventDates.class);
559+
transaction.insertOrUpdate(eventDates);
560+
});
561+
realm.close();
566562
}
567563

568564
public Completable saveEventDates(List<EventDates> eventDates) {
@@ -637,7 +633,7 @@ public static <K extends RealmObject> LiveRealmDataObject<K> asLiveDataForObject
637633
* Convert RealmResults to FilterableRealmLiveData
638634
*/
639635
public static <K extends RealmObject> FilterableRealmLiveData<K> asFilterableLiveData(RealmResults<K> data) {
640-
return new FilterableRealmLiveData<K>(data);
636+
return new FilterableRealmLiveData<>(data);
641637
}
642638

643639
/**

0 commit comments

Comments
 (0)