Flowable
がルームでどのように機能するのかを理解できません。私はgetSites()
によって返さFlowable
オブジェクトにupsert
加入者を呼び出したときに常に呼び出されることを期待して、このようなDao
方法Room Flowableは挿入時にデータを出力しません
@Insert(onConflict = OnConflictStrategy.REPLACE)
void upsert(List<Site> sites);
@Query("SELECT * FROM site ORDER BY distance ASC")
Flowable<List<Site>> getSites();
を持っています。私の前提は真実ですか?ここで
は私がupsert()
が呼び出された後に、この流動性のは呼び出されません。この流動性の
private final Flowable<List<Site>> siteFlowable;
ApiService apiService;
FuelDatabase database;
@Override
public void getSites(boolean showOnlyKeySites) {
// add sites from cache first, then fetch network -> update cache -> update ui
disposable = siteFlowable.flatMap(Flowable::fromIterable)
.filter(site -> site.isValid())
.buffer(100, TimeUnit.MILLISECONDS, 20)
.takeUntil(sites -> sites.size() == 0)
.observeOn(AndroidSchedulers.mainThread())
.doOnNext(mapView::addPins)
.subscribe(sites -> {
Timber.d("Flowable emitted %d items", sites.size());
}, Timber::e);
apiService.getSites()
.map(SiteListResponse::getData)
.flatMap(Observable::fromIterable)
.filter(Site::isValidSite)
.toList().toObservable()
.subscribe(sites -> {
Timber.i("Success Fetching %d sites", sites.size());
database.siteDao().clear();
database.siteDao().upsert(sites);
}, throwable -> Timber.e(throwable, "Error fetching sites"));
}
にsusbcribingい方法です。 APIが有効なデータを返していて、データがデータベースに入力されています。
私の知る限りルームクエリは 'toList'がそれらに動作しませんので、無限です。 https://stackoverflow.com/a/47260768/61158 – akarnokd
@akarnokdを参照してください。クエリーで 'toList()'はどこにありますか? –
私はtoObservable()の後にflatMapを使用して、別のフロー可能なストリームに変換する必要があると思っています – Rahul