Hi Eric,
> I'm trying to delete some unwanted data from my datastore and found
> some code using the DatastoreService that I modified to delete as many
> entries as possible in 10 seconds:
>
> DatastoreService datastore =
> DatastoreServiceFactory.getDatastoreService();
> Query query = new Query("PostalCodes");
> long starttime = (new Date()).getTime();
> for (Entity entity : datastore.prepare(query).asIterable()) {
> datastore.delete(entity.getKey());
> if ((new Date().getTime()) > (starttime + 10000))
> break;
> }
>
Your code looks like no problem, I do not know the reason
the whole thing has been restored. It is unusual.
Regarding the performance, the following code is faster:
DatastoreService ds =
DatastoreServiceFactory.getDatastoreService();
Query query = new Query("PostalCodes");
query.setKeysOnly();
long starttime = (new Date()).getTime();
while (new Date().getTime() - starttime <= 10000) {
List<Key> keys = new ArrayList<Key>();
for (Entity entity :
ds.prepare(query).asList(FetchOptions.Builder.withLimit(500))) {
keys.add(entity.getKey());
}
ds.delete(keys);
}
The points are setKeysOnly() and batch delete.
Hope this helps,
Yasuo Higa
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en
-~----------~----~----~----~------~----~------~--~---