Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Scale down statistic loading of documents in version page
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Apr 8, 2014
1 parent 18e8f56 commit aafa242
Showing 1 changed file with 50 additions and 35 deletions.
85 changes: 50 additions & 35 deletions zanata-war/src/main/java/org/zanata/action/VersionHomeAction.java
Expand Up @@ -36,6 +36,7 @@
import javax.faces.application.FacesMessage;
import javax.validation.ConstraintViolationException;

import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
Expand All @@ -47,6 +48,7 @@
import org.zanata.common.LocaleId;
import org.zanata.common.MergeType;
import org.zanata.common.ProjectType;
import org.zanata.dao.CredentialsDAO;
import org.zanata.dao.DocumentDAO;
import org.zanata.dao.LocaleDAO;
import org.zanata.dao.ProjectIterationDAO;
Expand Down Expand Up @@ -165,7 +167,7 @@ public class VersionHomeAction extends AbstractSortAction implements

private List<HDocument> documents;

private Map<LocaleId, WordStatistic> statisticMap;
private Map<LocaleId, WordStatistic> localeStatisticMap;

private Map<DocumentLocaleKey, WordStatistic> documentStatisticMap;

Expand All @@ -184,18 +186,12 @@ public class VersionHomeAction extends AbstractSortAction implements
@Getter
private SortingType documentSortingList = new SortingType(
Lists.newArrayList(SortingType.SortOption.ALPHABETICAL,
SortingType.SortOption.HOURS,
SortingType.SortOption.PERCENTAGE,
SortingType.SortOption.WORDS,
SortingType.SortOption.LAST_SOURCE_UPDATE,
SortingType.SortOption.LAST_TRANSLATED));

@Getter
private SortingType sourceDocumentSortingList = new SortingType(
Lists.newArrayList(SortingType.SortOption.ALPHABETICAL,
SortingType.SortOption.HOURS,
SortingType.SortOption.PERCENTAGE,
SortingType.SortOption.WORDS,
SortingType.SortOption.LAST_SOURCE_UPDATE));

@Getter
Expand Down Expand Up @@ -327,35 +323,24 @@ public void resetPageData() {

@Override
protected void loadStatistics() {
statisticMap = Maps.newHashMap();
localeStatisticMap = Maps.newHashMap();
for (HLocale locale : getSupportedLocale()) {
WordStatistic wordStatistic =
versionStateCacheImpl.getVersionStatistics(getVersion()
.getId(), locale.getLocaleId());
wordStatistic.setRemainingHours(StatisticsUtil
.getRemainingHours(wordStatistic));
statisticMap.put(locale.getLocaleId(), wordStatistic);
localeStatisticMap.put(locale.getLocaleId(), wordStatistic);
}

overallStatistic = new WordStatistic();
for (Map.Entry<LocaleId, WordStatistic> entry : statisticMap.entrySet()) {
for (Map.Entry<LocaleId, WordStatistic> entry : localeStatisticMap.entrySet()) {
overallStatistic.add(entry.getValue());
}
overallStatistic.setRemainingHours(StatisticsUtil
.getRemainingHours(overallStatistic));

documentStatisticMap = Maps.newHashMap();
for (HDocument document : getDocuments()) {
for (HLocale locale : getSupportedLocale()) {
WordStatistic wordStatistic =
documentDAO.getWordStatistics(document.getId(),
locale.getLocaleId());
wordStatistic.setRemainingHours(StatisticsUtil
.getRemainingHours(wordStatistic));
documentStatisticMap.put(new DocumentLocaleKey(
document.getId(), locale.getLocaleId()), wordStatistic);
}
}
}

@Override
Expand Down Expand Up @@ -383,6 +368,13 @@ public List<HDocument> getDocuments() {
return documents;
}

public List<HDocument> getDocuments(DocumentDAO documentDAO) {
if (this.documentDAO == null) {
this.documentDAO = documentDAO;
}
return getDocuments();
}

public List<HDocument> getSourceDocuments() {
if (documents == null) {
documents =
Expand All @@ -393,6 +385,13 @@ public List<HDocument> getSourceDocuments() {
return documents;
}

public List<HDocument> getSourceDocuments(DocumentDAO documentDAO) {
if (this.documentDAO == null) {
this.documentDAO = documentDAO;
}
return getSourceDocuments();
}

public List<HIterationGroup> getGroups() {
if (groups == null) {
HProjectIteration version = getVersion();
Expand Down Expand Up @@ -431,23 +430,31 @@ public class DocumentLocaleKey {
}

public WordStatistic getStatisticsForLocale(LocaleId localeId) {
return statisticMap.get(localeId);
return localeStatisticMap.get(localeId);
}

public WordStatistic getStatisticForDocument(Long documentId,
LocaleId localeId) {
return documentStatisticMap.get(new DocumentLocaleKey(documentId,
localeId));
DocumentLocaleKey key = new DocumentLocaleKey(documentId, localeId);
if (!documentStatisticMap.containsKey(key)) {
WordStatistic wordStatistic =
documentDAO.getWordStatistics(documentId, localeId);
wordStatistic.setRemainingHours(StatisticsUtil
.getRemainingHours(wordStatistic));
documentStatisticMap.put(key, wordStatistic);
}
return documentStatisticMap.get(key);
}

public WordStatistic getDocumentStatistic(Long documentId) {
WordStatistic wordStatistic = new WordStatistic();
for (Map.Entry<DocumentLocaleKey, WordStatistic> entry : documentStatisticMap
.entrySet()) {
if (entry.getKey().getDocumentId().equals(documentId)) {
wordStatistic.add(entry.getValue());
}

for (HLocale locale : getSupportedLocale()) {
WordStatistic statistic =
getStatisticForDocument(documentId, locale.getLocaleId());
wordStatistic.add(statistic);
}

wordStatistic.setRemainingHours(StatisticsUtil
.getRemainingHours(wordStatistic));
return wordStatistic;
Expand Down Expand Up @@ -840,17 +847,24 @@ public void uploadTranslationFile(HLocale hLocale) {
}

private class DocumentFilter extends AbstractListFilter<HDocument> {
private DocumentDAO documentDAO = (DocumentDAO) Component
.getInstance(DocumentDAO.class);

@Override
protected List<HDocument> getFilteredList() {
return FilterUtil.filterDocumentList(getQuery(), getDocuments());
return FilterUtil.filterDocumentList(getQuery(),
getDocuments(documentDAO));
}
};

private class SourceDocumentFilter extends AbstractListFilter<HDocument> {
private DocumentDAO documentDAO = (DocumentDAO) Component
.getInstance(DocumentDAO.class);

@Override
protected List<HDocument> getFilteredList() {
return FilterUtil.filterDocumentList(getQuery(),
getSourceDocuments());
getSourceDocuments(documentDAO));
}
};

Expand Down Expand Up @@ -904,11 +918,12 @@ public int compare(HDocument o1, HDocument o2) {
WordStatistic wordStatistic2;
if (selectedLocaleId != null) {
wordStatistic1 =
documentStatisticMap.get(new DocumentLocaleKey(
item1.getId(), selectedLocaleId));
getStatisticForDocument(item1.getId(),
selectedLocaleId);

wordStatistic2 =
documentStatisticMap.get(new DocumentLocaleKey(
item2.getId(), selectedLocaleId));
getStatisticForDocument(item2.getId(),
selectedLocaleId);

} else {
wordStatistic1 = getDocumentStatistic(item1.getId());
Expand Down

0 comments on commit aafa242

Please sign in to comment.