Sped up loading all speeches, still slow
This commit is contained in:
parent
861e14b64d
commit
a071ad253f
5 changed files with 45 additions and 24 deletions
|
@ -520,30 +520,46 @@ public class MongoPprUtils {
|
|||
* @return
|
||||
*/
|
||||
public static List<SpeechMetaData> getSpeechesMetadata(String filter) {
|
||||
|
||||
List<SpeechMetaData> speechMetaDataList = new ArrayList<>();
|
||||
List<Speech> speeches = MongoPprUtils.getSpeeches(filter);
|
||||
for (Speech speech : speeches) {
|
||||
SpeechMetaData md = new SpeechMetaData();
|
||||
|
||||
md.setSpeechKey(speech.getSpeechKey());
|
||||
md.setSpeechId(speech.getSpeechId());
|
||||
md.setSpeakerId(speech.getSpeakerId());
|
||||
md.setSpeakerName(speech.getSpeakerName());
|
||||
md.setFraktion(speech.getFraction());
|
||||
if (md.getFraktion() == null) {md.setFraktion(PPRUtils.PARTEILOS_KUERZEL);}
|
||||
int sessionId = speech.getSessionId();
|
||||
md.setSessionId(sessionId);
|
||||
MongoCursor<Document> cursor;
|
||||
|
||||
// aus "sessions" Collection
|
||||
augmentSpeechMetaDataFromSession(sessionId, md);
|
||||
if (filter== null || filter.isBlank()) {
|
||||
cursor = getSpeechCollection().find().iterator();
|
||||
} else {
|
||||
String pattern = ".*" + filter + ".*";
|
||||
Document searchDocument = new Document("$or", List.of(
|
||||
new Document("speakerName", new Document("$regex", pattern).append("$options", "i")),
|
||||
new Document("fraction", new Document("$regex", pattern).append("$options", "i")),
|
||||
new Document("speechKey", new Document("$regex", pattern).append("$options", "i"))
|
||||
));
|
||||
cursor = getSpeechCollection().find(searchDocument).cursor();
|
||||
}
|
||||
|
||||
// aus "agendaItems" Collection
|
||||
int agendaItemId = speech.getAgendaItemId();
|
||||
String agendaTitel = getAgendaTitle(sessionId, agendaItemId);
|
||||
md.setAgendaTitle(agendaTitel);
|
||||
try {
|
||||
while (cursor.hasNext()) {
|
||||
Document doc = cursor.next();
|
||||
SpeechMetaData smd = new SpeechMetaData();
|
||||
smd.setSpeechKey(doc.getString("speechKey"));
|
||||
Date dateTimeInMongo = doc.getDate("dateTime");
|
||||
smd.setDateTime(LocalDateTime.ofInstant(dateTimeInMongo.toInstant(), ZoneId.systemDefault()));
|
||||
smd.setDateTimeString(doc.getString("dateTimeString"));
|
||||
smd.setSpeakerName(doc.getString("speakerName"));
|
||||
String fraktion = (doc.getString("fraction"));
|
||||
if (fraktion == null) {
|
||||
smd.setFraktion(PPRUtils.PARTEILOS_KUERZEL);
|
||||
} else {
|
||||
smd.setFraktion(fraktion);
|
||||
}
|
||||
smd.setAgendaTitle(doc.getString("agendaTitel"));
|
||||
smd.setSpeakerId(doc.getInteger("speakerId"));
|
||||
|
||||
speechMetaDataList.add(md);
|
||||
speechMetaDataList.add(smd);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
Logger.error(String.valueOf(t));
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
// Sortiere nach Datum, absteigend
|
||||
|
@ -557,6 +573,7 @@ public class MongoPprUtils {
|
|||
return speechMetaDataList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Füge Rede-Metadaten (welche in der Session-Collection stehen) der Rede hinzu.
|
||||
* Achtung: Redezeit ist in der Datenbank in unterschiedlichen Formaten vorhanden.
|
||||
|
@ -608,7 +625,8 @@ public class MongoPprUtils {
|
|||
if ((iter == null || (iter.first() == null))) {
|
||||
return "(kein Agendatitel)";
|
||||
} else {
|
||||
return (String) iter.first().get("title");
|
||||
String agendaTitel = (String) iter.first().get("title");
|
||||
return String.format("%d / %s", sessionId, agendaTitel);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -689,7 +707,6 @@ public class MongoPprUtils {
|
|||
Document groupStage = new Document("$group", new Document("_id", "$topics")); // Group by "topics"
|
||||
Document projectStage = new Document("$project", new Document("topic", "$_id").append("_id", 0)); // Optionally format the result
|
||||
|
||||
// Execute the aggregation
|
||||
AggregateIterable<Document> result = getSpeechCollection().aggregate(Arrays.asList(unwindStage, groupStage, projectStage));
|
||||
Set<String> topics = new HashSet<>();
|
||||
for (Document doc : result) {
|
||||
|
|
|
@ -104,7 +104,7 @@ public class ParlamentarierController {
|
|||
|
||||
// Foto des Abgeordnetes
|
||||
String picture = MongoPprUtils.getParlamentarierPictureByID(id);
|
||||
attributes.put("pic", picture);
|
||||
attributes.put("picture", picture);
|
||||
|
||||
ctx.render("parlamentarierDetails.ftl", attributes);
|
||||
}
|
||||
|
|
|
@ -200,6 +200,10 @@ public class SpeechController {
|
|||
return iconNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeige alle Reden
|
||||
* @param ctx
|
||||
*/
|
||||
@OpenApi(
|
||||
summary = "Liste alle Reden (Filtern ist möglich)",
|
||||
description = "Liste alle Reden. Man kann nach Freitext (MdB Name, Partei/Fraktion) oder nach Thema (Topic) filtern",
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
<td>${redeMd.dateTimeString}</td>
|
||||
<td>${redeMd.speakerName}</td>
|
||||
<td>${redeMd.fraktion}</td>
|
||||
<td><a href="/reden/${redeMd.speakerId}/${redeMd.speechKey}">${redeMd.sessionId} / ${redeMd.agendaTitle}</a></td>
|
||||
<td><a href="/reden/${redeMd.speakerId?string("0")}/${redeMd.speechKey}">${redeMd.agendaTitle}</a></td>
|
||||
</tr>
|
||||
</#list>
|
||||
</tbody>
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
<#list speechesMetaDataList as redeMd>
|
||||
<tr>
|
||||
<td>${redeMd.dateTimeString}</td>
|
||||
<td><a href="/reden/${p.id}/${redeMd.speechKey}">${redeMd.sessionId} / ${redeMd.agendaTitle}</a></td>
|
||||
<td><a href="/reden/${p.id}/${redeMd.speechKey}">${redeMd.agendaTitle}</a></td>
|
||||
</tr>
|
||||
</#list>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue