getRecentDocumentを非同期に

This commit is contained in:
r-ca 2024-01-20 23:17:31 +09:00
parent 4ab13508c4
commit 4e5aab276a
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9

View File

@ -2,7 +2,9 @@ package one.nem.lacerta.data.impl;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture;
import javax.inject.Inject; import javax.inject.Inject;
@ -28,23 +30,26 @@ public class LacertaLibraryImpl implements LacertaLibrary {
} }
@Override @Override
public ArrayList<ListItem> getRecentDocument(int limit) { public CompletableFuture<ArrayList<ListItem>> getRecentDocument(int limit) {
List<DocumentEntity> documentEntities = database.documentDao().getRecentDocument(limit); return CompletableFuture.supplyAsync(() -> {
List<DocumentEntity> documentEntities = database.documentDao().getRecentDocument(limit);
ArrayList<ListItem> listItems = new ArrayList<>(); ArrayList<ListItem> listItems = new ArrayList<>();
for (DocumentEntity documentEntity : documentEntities) { for (DocumentEntity documentEntity : documentEntities) {
ListItem listItem = new ListItem(); ListItem listItem = new ListItem();
listItem.setItemType(ListItemType.ITEM_TYPE_DOCUMENT); listItem.setItemType(ListItemType.ITEM_TYPE_DOCUMENT);
listItem.setTitle(documentEntity.title); listItem.setTitle(documentEntity.title);
listItem.setDescription(DateFormat.getDateInstance().format(documentEntity.updatedAt)); listItem.setDescription(DateFormat.getDateInstance().format(documentEntity.updatedAt));
listItem.setItemId(documentEntity.id); listItem.setItemId(documentEntity.id);
listItems.add(listItem); listItems.add(listItem);
} }
return listItems;
return listItems;
});
} }
@Override @Override
public ArrayList<ListItem> getRecentDocument(int limit, int offset) { public CompletableFuture<ArrayList<ListItem>> getRecentDocument(int limit, int offset) {
return null; // TODO-rca: Implement return null; // TODO-rca: Implement
} }