-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query cache and use setParameters not working properly #927
Comments
It might speedup response time if you could show the relevant code parts directly in the ticket. |
Thank you very much for your reply. The main code is as follows: @Entity
public class Message {
private static Map<String, Query<Message>> queryMap = new ConcurrentHashMap<>(5);
public static List<Message> getMsgList(String sid, boolean isDesc) {
try {
String keyName = "getMsgList".concat(isDesc ? "1" : "2");
Query<Message> query = queryMap.get(keyName);
if (query == null) {
QueryBuilder<Message> queryBuilder =
StoreManager.getBoxStore().boxFor(Message.class).query().equal(Message_.sid, sid);
query = (isDesc ? queryBuilder.orderDesc(Message_.serverId) : queryBuilder.order(Message_.serverId)).build();
queryMap.put(keyName, query);
} else {
query.setParameter(Message_.sid, sid);
}
return query.find();
} catch (Exception e) {
return new LinkedList<>();
}
}
public static List<Message> getMsgListWithType(String sid, int[] types, boolean isDesc) {
try {
String keyName = "getMsgListWithType".concat(isDesc ? "1" : "2");
Query<Message> query = queryMap.get(keyName);
if (query == null) {
QueryBuilder<Message> queryBuilder = StoreManager.getBoxStore().boxFor(Message.class).query()
.equal(Message_.sid, sid)
.in(Message_.tp, types);
query = (isDesc ? queryBuilder.orderDesc(Message_.serverId) : queryBuilder.order(Message_.serverId)).build();
queryMap.put(keyName, query);
} else {
query.setParameter(Message_.sid, sid).setParameters(Message_.tp, types);
}
return query.find();
} catch (Exception e) {
return new LinkedList<>();
}
}
public static List<Message> getMsgListWithType2(String sid, int[] types, boolean isDesc) {
try {
String keyName = "getMsgListWithType2".concat(isDesc ? "1" : "2");
Query<Message> query = queryMap.get(keyName);
if (query == null) {
QueryBuilder<Message> queryBuilder = StoreManager.getBoxStore().boxFor(Message.class).query()
.equal(Message_.sid, sid)
.in(Message_.tp, types).parameterAlias("1");
query = (isDesc ? queryBuilder.orderDesc(Message_.serverId) : queryBuilder.order(Message_.serverId)).build();
queryMap.put(keyName, query);
} else {
query.setParameter(Message_.sid, sid).setParameters("1", types);
}
return query.find();
} catch (Exception e) {
return new LinkedList<>();
}
}
@Id
public long id;
@Index
public long serverId; // 消息id
@Index
public String fr; // 发送者用户名
public int tp; // 消息类型
public int s; // 发送平台
public String m;
public String fn; // 发送者名字
public String nn; // 发送者昵称,在昵称发生变化时,需要进行对应消息的更新.
public long ts; // 发送时间
public String oz; // 扩展字段
public String at; // 是否有@别人
@Index
public String sid; // topicId
public Message(int tp, String sid, String m) {
this.tp = tp;
this.sid = sid;
this.m = m;
}
} method getMsgListWithType use setParameters(Property<?> property, int[] values) not work |
I didn't see anything obvious with your code. 🤔 Maybe this helps: this unit test ensures that PS.: is queryMap the same static instance? That would explain it. You need to use different keys for different queries. |
sorry,the testCase code is below:
the testcase log is below:
the question is: |
the queryMap is static for the three methods and the query cache keys of the three methods are all different。 |
Played with the given example and indeed it looks like Query<Message> query = queryMap.get(keyName);
if (query == null) {
QueryBuilder<Message> queryBuilder = StoreManager.getBoxStore().boxFor(Message.class).query()
.equal(Message_.sid, "")
.in(Message_.tp, new int[]{});
query = (isDesc ? queryBuilder.orderDesc(Message_.serverId) : queryBuilder.order(Message_.serverId)).build();
queryMap.put(keyName, query);
}
query.setParameter(Message_.sid, sid).setParameters(Message_.tp, types);
return query.find(); so However, I can't reproduce this (it's not about multiple conditions, not about I'll try to create a minimal example that copies what the given example does, and maybe I'll find something. Edit: query parameters also look fine:
|
Thank you very much for your reply. |
@ffyliu You found a bug, thank you! It appears this only affects the Android 32-bit libraries (so x86 and armeabi-v7) running on 64-bit devices. The 64-bit libraries (x86_x64, arm64-v8a), which most devices probably use are not affected. Update: running the Android 32-bit libraries on 32-bit devices also do not have this issue. Your
You should update (or even remove) your ABI filters to include the 64-bit libraries. ObjectBox only supports x86, x86_x64, armeabi-v7, arm64-v8a. |
OK,I will remove my app ndk filters and retry。 @greenrobot-team I change the ndk filters to below |
Update: this issue only occurs when running the Android 32-bit libraries (x86 and armeabi-v7) on 64-bit capable hardware. In the above case the use of ABI filters excluded the 64-bit libraries. Removing/updating the ABI filters so the 64-bit libraries are included resolves this issue. Projects that do not exclude the 64-bit libraries are not affected. Put differently: the 32-bit Android libraries (x86 and armeabi-v7) work fine on 32-bit hardware. Regardless, a fix to support running the 32-bit lib on 64-bit hardware exists internally and will be released in an upcoming release. Updated my message above in that regard. Side note: since August 2019 Play Store requires new apps and app updates to ship 64-bit versions of native libraries. |
Running the x86 Android library on x64 hardware should be possible again with the upcoming |
🚨 First, please check:
Describe the bug
When I query data, I cache the query object and do the query, the result is normal. Then the next same method query uses setParameters method to modify parameters, and the result is not right.
Basic info (please complete the following information):
attachments are corresponding demo
1.compile and install apk
2.start the app and click on the database test in the upper right corner
3.click the bottom button and check the log.
demo explanation:
Entity:Message
method getMsgListWithType use setParameters(Property<?> property, int[] values) not work
method getMsgListWithType2 use setParameters(String alias, int[] values) not work
method getMsgList use setParameter work right.
TestAll.zip
The text was updated successfully, but these errors were encountered: