Breeze - run metadata only once - breeze

I have three query against the server. Before each query breeze run "Metadata". Is there a way to run this function only once? I think there is no need for it, because the model hasn't changed.

Without more information, the only reason that i can think that can make breeze to ask for metadata in each query is because you are not reusing the manager and you are creating a new manager for each query.
If that is the reason, you can see this section of the documentation where is explained how to share a single entity manager:
http://www.breezejs.com/documentation/share-entitymanager

Related

DynamoDB AWS best way to retrieve data in a recurring way

So as the question states, I have a dynamoDB setup from which I am fetching data. My User end is configured in iOS, hence I am using the AWS iOS SDK. Although the documentation is alright, but its outdated a lot, and going through the documentations, many classes are deprecated.
I have 2 questions -
I have to fetch the latest entry from the DB always, so I am doing this by setting the scanforward = false and limit = 1 . Now I am calling query method from the dynamoDBObjectMapper, but there is also load method which also can be configured to do the same. My first question is that what is the difference between query and load if I have to fetch only the latest entry in the DB. Also what is the correct way to retrieve it?
I have to fetch this data in the most instantaneous way possible. I know about DynamoDBStream, but that is NOT an option. Basically I have to implement a long polling kind of feature, where I will get a call? whenever any data is changed OR continuously fetch data from the dynamoDB at a particular interval. Shall i use NSTimer and the same method call (load vs query) to fetch the latest entry in the DB?
Any help is greatly appreciated. Also if any developer working in Amazon can see this question, please remove the old documentation from AWS console and keep the latest ones. There are 5 documentation on the same thing, and all of them are outdated and deprecated.
Thanks for pointing that out. Can you give the links of the documentation that has deprecated classes? We will try to keep the latest ones and remove if there are any redundant deprecated references.
load() API is used to retrieve an item: Using an object's primary key load the corresponding item from the database. Look for an example here: http://docs.aws.amazon.com/mobile/sdkforios/developerguide/dynamodb-object-mapper.html under "Retrieve an item" section.
query() API can be used to return any number of records that match the query. The query API enables you to query a table or a secondary index.
To answer your question, if you know the primary key of the record that you are trying to retrieve, you can use load() API, otherwise use query() API.
DynamoDBStreams work well for your use case. Otherwise you can intgerate AWS Lambda with DynamoDB table to do polling which will be cleaner than a timer based approach. This question is partially answered here: Hooks for AWS DynamoDB streams

How to avoid duplicated records in core data - ios

I'm new in iOS, Swift. My application has one entity named "Category" in a relationship to many entities named "Movies".
"Movies" entities are changing, according to data that I get from a url. I'm looking for a way not to have duplicated movies records in each category, and I can't think of an easy way to do it.
Core-data does not have a built in way to ensure uniqueness. You have to manage that yourself. But it is not that hard. Before every insert/update do a fetch - if it does not exist then create it, it if already exists then update it. If you are updating many at a time (for example from a network request that has updates for many entities) then fetch all of then in a single fetch request and then create or update as needed.
Generally these fetches are done using uniqueIds for each entity. If you don't have any uniqueId for you entities then you have a deeper problem than core data. You could have two movies with the same name, or one movie that has different names. If you don't have anything that says the same, then you fundamentally don't have any way to know if you need to make another entity or update an existing one. It is possible that you can use the movie name, but I would not recommend that. I suggest that you look closer at your server api and see if there is a uniqueId that is served, and if there is none then you have to have it fixed by the server team.

Should we use the Neo4J internal id?

We are currently working with a Neo4j database, and we need some kind of id to identify nodes.
For example we have functions like CurrentUserHasAccess(NodeId)
On other Stackoverflow posts I read that it's a bad idea to use the internal neo4j-identifier, because it can change over time. However I think that's not an issue when we do not use this id to link data.
However I cannot seem to find any official sources about this topic.
I would like to use this ID because then we do not need to worry about uniqueness, and more importantly indexing.
You are right that it is generally not recommended to use the internal Neo4j node IDs. This is mainly because if a node gets deleted, its original internal ID may get recycled/reused. If you're looking for a quick and elegant solution to this, have a look at the UUID module of the GraphAware Framework here https://github.com/graphaware/neo4j-uuid and let us know if it works for you.

is there an easy way to mark an entity in the cache as "added"?

i would like to set an entity sent from the server to "added". it looks like entityaspect has methods setdeleted, setmodified, etc... but i can't seem to find one called setadded... what is the cleanest way to set an entity to "added"? i was thinking perhaps i would need to detach and then attach as "added". i have a server method called "newdeal" which creates a new entity ready for data entry... this method has business logic which i would prefer to keep on the server... when it gets to the client the entity is marked as "unmodified" which makes sense... but i would then like to change it to "added"...
thank you
#giancarloa, I'm assuming that, by the time the entity is sent from server to client, it has been persisted in the database. If that's the case, it wouldn't make sense to have its entityState set to Added as it would cause a duplicate error. If that's not how it works, please explain in detail what you are doing as I'm trying to get an idea of all the steps you're taking.
I'm also confused as to why create an entity in the server, send it to the client, update it, and then send it back to the server to save it in the DB - this just appear to cause more traffic and possibly reduce performance. Also, what it the user decides not to save? - then the work in the server would've been wasted.
Why not create the entity in the client and if it turns out to be saved, then the business logic would kick in the server during the beforeSaveEntity/beforeSaveEntities?
I had a similar problem. The breeze expect that entities returned from the server already exists in your database. This is not the case if your server fetched the entities from some other sources (not the database), returned them to client and then user can decide to the client if those entities should really be inserted in the database.
As you indicated, what you must do is skip the code that adds the entities into client's entity manager. later, you can add the detached entities to Entitymanager.
See the following answer for more details.
https://stackoverflow.com/a/18596070/174638

Synchronization with RestKit

I'm about to write a simple iPhone app that uses Core Data to store local copy of remote data that is fetched via RESTful web service. The data changes (new records being added) quite often. I came across RestKit and I'm wondering if it can do what I need. And what I need is to load all records in the beginning and then periodically download ONLY records that were added since previous check. Obviously there is no mystery about how that can be accomplished even by simply using NSURLConnection, but I hoped RestKit (probably in combination with a proper web service) would do that without me having to write all the synchronization logic. Again the key for me is that only new/changed data is fetched from the server.
I agree - RestKit can do this, we've recently used it to do something similar in a recent project. We used a last-modified-date request header to indicate the last successful 'sync' time, which the server can use to return only the records modified since that date. A http 304 'not modified' status code was used to indicate no change when appropriate.
RestKit also includes a seeding facility, so you know up front the initial data set - you can seed it as the initial database easily, and fetch the updates, even upon first use of the application.
Some information I found useful regarding RestKit & CoreData mapping - https://github.com/RestKit/RestKit/blob/master/Docs/Object%20Mapping.md, and the Google group is a good source as well - https://groups.google.com/group/restkit. Hope this all helps.
First of all: YES
RestKit handles CoreData very well. All you need to do is to provide mapping of your entities and it does the work for you.
For the second thing about selective sync, I really recommend checking StorageRoomApp it is a great, and not so expensive service that does exactly what you need.
They have a very good API that extends RestKit, it is very easy to use and their support is great. Take a look.

Resources