mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-20 23:57:46 +01:00
Detcach samples from the session after querying, to save memory
This commit is contained in:
parent
fb30321cca
commit
bfaaed7e5c
@ -93,9 +93,20 @@ public abstract class AbstractSampleProvider<T extends AbstractActivitySample> i
|
|||||||
for (T sample : samples) {
|
for (T sample : samples) {
|
||||||
sample.setProvider(this);
|
sample.setProvider(this);
|
||||||
}
|
}
|
||||||
|
detachFromSession();
|
||||||
return samples;
|
return samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detaches all samples of this type from the session. Changes to them may not be
|
||||||
|
* written back to the database.
|
||||||
|
*
|
||||||
|
* Subclasses should call this method after performing custom queries.
|
||||||
|
*/
|
||||||
|
protected void detachFromSession() {
|
||||||
|
getSampleDao().detachAll();
|
||||||
|
}
|
||||||
|
|
||||||
private WhereCondition[] getClauseForActivityType(QueryBuilder qb, int activityTypes) {
|
private WhereCondition[] getClauseForActivityType(QueryBuilder qb, int activityTypes) {
|
||||||
if (activityTypes == ActivityKind.TYPE_ALL) {
|
if (activityTypes == ActivityKind.TYPE_ALL) {
|
||||||
return NO_CONDITIONS;
|
return NO_CONDITIONS;
|
||||||
|
@ -9,6 +9,10 @@ import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
|||||||
/**
|
/**
|
||||||
* Interface to retrieve samples from the database, and also create and add samples to the database.
|
* Interface to retrieve samples from the database, and also create and add samples to the database.
|
||||||
* There are multiple device specific implementations, this interface defines the generic access.
|
* There are multiple device specific implementations, this interface defines the generic access.
|
||||||
|
*
|
||||||
|
* Note that the provided samples must typically be considered read-only, because they are immediately
|
||||||
|
* removed from the session before they are returned.
|
||||||
|
*
|
||||||
* @param <T> the device/provider specific sample type (must extend AbstractActivitySample)
|
* @param <T> the device/provider specific sample type (must extend AbstractActivitySample)
|
||||||
*/
|
*/
|
||||||
public interface SampleProvider<T extends AbstractActivitySample> {
|
public interface SampleProvider<T extends AbstractActivitySample> {
|
||||||
|
@ -57,6 +57,7 @@ public class PebbleHealthSampleProvider extends AbstractSampleProvider<PebbleHea
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
detachFromSession();
|
||||||
return samples;
|
return samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ public class EntitiesTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws GBException {
|
public void setUp() throws GBException {
|
||||||
|
// doesn't work with Robolectric yet
|
||||||
// dbHandler = GBApplication.acquireDB();
|
// dbHandler = GBApplication.acquireDB();
|
||||||
// daoSession = dbHandler.getDaoSession();
|
// daoSession = dbHandler.getDaoSession();
|
||||||
DaoMaster.DevOpenHelper openHelper = new DaoMaster.DevOpenHelper(app, null, null);
|
DaoMaster.DevOpenHelper openHelper = new DaoMaster.DevOpenHelper(app, null, null);
|
||||||
|
Loading…
Reference in New Issue
Block a user