Android アプリ用に Google App Engine を介してオンライン リーダーボードを実装しました。しかし、2 時間後、「データストアの読み取り操作」でクォータの 100% に達しました。読み取り操作を減らすためにコードを変更するのを手伝ってくれる人はいますか?
これが私のコードです:
public class The_Big_Bang_Theory_Quiz_HighscoreserverServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String game = req.getParameter("game");
String name = req.getParameter("name");
String pointsStr = req.getParameter("points");
String behaviorStr = req.getParameter("behavior");
int behavior = 0; // 0 = upload, 1 = download
if (behaviorStr != null) {
try {
behavior = Integer.parseInt(behaviorStr);
} catch (NumberFormatException e) {
behavior = 0;
}
}
if (behavior == 0) {
int points = 0;
if (pointsStr != null) {
try {
points = Integer.parseInt(pointsStr);
} catch (NumberFormatException e) {
points = 0;
}
}
if (points > 0 && name != null) {
addHighscore(game, name, points);
}
} else {
String maxStr = req.getParameter("max");
int max = 1000;
if (maxStr != null) {
try {
max = Integer.parseInt(maxStr);
} catch (NumberFormatException e) {
max = 1000;
}
}
returnHighscores(resp, game, max);
}
}
private void returnHighscores(HttpServletResponse resp, String game, int max) {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key gameKey = KeyFactory.createKey("game", game);
Query query = new Query("highscore", gameKey);
query.addSort("points", Query.SortDirection.DESCENDING);
List<Entity> highscores = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(max));
for(Entity e : highscores) {
try {
resp.getWriter().println(e.getProperty("name") + ";" +e.getProperty("points"));
} catch (IOException exc) {
exc.printStackTrace();
}
}
}
private void addHighscore(String game, String name, int points) {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key gameKey = KeyFactory.createKey("game", game);
Entity highscore = new Entity("highscore", gameKey);
highscore.setProperty("name", name);
highscore.setProperty("points", points);
datastore.put(highscore);
}
}
について何かを読みましたBlobStore
。それはより良い方法ですか?