-
Notifications
You must be signed in to change notification settings - Fork 173
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
Create new object and specify primary key WITHOUT db query? #94
Comments
Is it possible that |
@apalancat It's likely that Also, if you see my second edit, |
Yeah that shouldn't generate errors, no. It's very similar to what I'm doing, the main difference is that I don't use an |
My primary keys are strings generated on the server and guaranteed to be unique. Any tips to debug exactly what it's doing? If I break inside a save block, I only see the proper data, including the postId from the server. |
Based on the errors seems like it's doing an insert when should be doing an update? If that's the case, the |
I added some logs. It's definitely doing a double-insert, instead of an update. The funny thing is, both times there's all of the data, including the primary key. The duplicate saves are milliseconds apart, so this might have to do with creating the object and then immediately updating it before it's done being inserted to the db?
|
It seems that the DB thread is (dun-dun-duuun) concurrency issue 😱 |
@apalancat Managed to track down the concurrency issue, which wasn't an issue until we rewrote our regex in c, I guess (it calls back to the main thread:60b within milliseconds now). But this raises another question: is this framework purposely not doing any thread-safe kind of functions? Also I was overriding |
Usually concurrency is fine, since DB access is synchronous. But seems like you found an edge case. As far as I understand the issue is:
A solution could be to add a semaphore to @mtitolo Do you feel that's an accurate description of the issue? |
If the problem is as @apalancat is describing, this should already be fixed by 7f64fa7, which moved the whole |
See edits below. My console gets flooded with these errors:
I'm manually creating Links with alloc/init, then using EasyMapping to fill them with data from a JSON response.
It does not appear that I can alloc/init and then specify the primary key. The PK I'm using comes from the server, and is guaranteed to be unique. It is not supposed to be generated on the client, so I cannot reliably override
primaryKeyValueForNewInstance
, which it looks likeinit
calls.So: how should I create new objects and specify a primary key without querying for them?
Edit: After more digging, the DB error comes from the fact that
primaryKeyValueForNewInstance
is somehow creating duplicate keys...Edit 2: Switching to
[Link instanceWithPrimaryKey:JSONDictionary[@"data"][@"id"]];
does not stop the flood of these error messages...The text was updated successfully, but these errors were encountered: