Skip to content

Commit

Permalink
Improvement of pology feature performance
Browse files Browse the repository at this point in the history
- Disable the option by default
- Limit the number of processes launched to one at a time
- Do not block waiting for the KProcess to finish
- Code clean-up
  • Loading branch information
LlianeFR committed Sep 22, 2018
1 parent 9b909e7 commit a4e1034
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
39 changes: 25 additions & 14 deletions src/msgctxtview.cpp
Expand Up @@ -72,6 +72,8 @@ MsgCtxtView::~MsgCtxtView()
{
}

const QString MsgCtxtView::BR = "<br />";

void MsgCtxtView::cleanup()
{
m_unfinishedNotes.clear();
Expand Down Expand Up @@ -106,14 +108,13 @@ void MsgCtxtView::process()
m_prevEntry = m_entry;
m_browser->clear();

static const QString BR = QStringLiteral("<br />");
if (m_tempNotes.contains(m_entry.entry)) {
QString html = i18nc("@info notes to translation unit which expire when the catalog is closed", "<b>Temporary notes:</b>");
html += BR;
html += MsgCtxtView::BR;
foreach (const QString& note, m_tempNotes.values(m_entry.entry))
html += note.toHtmlEscaped() + BR;
html += BR;
m_browser->insertHtml(html.replace('\n', BR));
html += note.toHtmlEscaped() + MsgCtxtView::BR;
html += MsgCtxtView::BR;
m_browser->insertHtml(html.replace('\n', MsgCtxtView::BR));
}

QString phaseName = m_catalog->phase(m_entry.toDocPosition());
Expand All @@ -125,7 +126,7 @@ void MsgCtxtView::process()
html += phase.process.toHtmlEscaped();
if (!phase.contact.isEmpty())
html += QString(QStringLiteral(" (%1)")).arg(phase.contact.toHtmlEscaped());
m_browser->insertHtml(html + BR);
m_browser->insertHtml(html + MsgCtxtView::BR);
}

const QVector<Note> notes = m_catalog->notes(m_entry.toDocPosition());
Expand All @@ -137,7 +138,7 @@ void MsgCtxtView::process()

QString html;
foreach (const Note& note, m_catalog->developerNotes(m_entry.toDocPosition())) {
html += BR + escapeWithLinks(note.content);
html += MsgCtxtView::BR + escapeWithLinks(note.content);
}

QStringList sourceFiles = m_catalog->sourceFiles(m_entry.toDocPosition());
Expand All @@ -164,7 +165,7 @@ void MsgCtxtView::process()
}
void MsgCtxtView::pology()
{
if (Project::instance()->local()->pologyEnabled()) {
if (Project::instance()->local()->pologyEnabled() && !m_pologyProcessInProgress) {
QString command = Project::instance()->local()->pologyCommandEntry();
command = command.replace(QStringLiteral("%u"), QString::number(m_entry.entry + 1)).replace(QStringLiteral("%f"), m_catalog->url()).replace(QStringLiteral("\n"), QStringLiteral(" "));
m_pologyProcess = new KProcess;
Expand All @@ -178,36 +179,45 @@ void MsgCtxtView::pology()
connect(m_pologyProcess, QOverload<int>::of(&KProcess::finished),
this, &MsgCtxtView::pologyHasFinished);
m_pologyData = QStringLiteral("[pology] ");
m_pologyProcessInProgress = true;
m_pologyProcess->start();
m_pologyProcess->waitForFinished();
}
}
void MsgCtxtView::pologyReceivedStandardOutput()
{
if (!m_pologyStartedReceivingOutput) {
m_pologyStartedReceivingOutput = true;
}
static const QString grossPologyOutput = m_pologyProcess->readAllStandardOutput();
static const QStringList pologyTmpLines = grossPologyOutput.split('\n', QString::SkipEmptyParts);
const QString grossPologyOutput = m_pologyProcess->readAllStandardOutput();
const QStringList pologyTmpLines = grossPologyOutput.split('\n', QString::SkipEmptyParts);
foreach (const QString pologyTmp, pologyTmpLines) {
if (pologyTmp.startsWith(QStringLiteral("[note]")))
m_pologyData += pologyTmp;
}
}


void MsgCtxtView::pologyReceivedStandardError()
{
if (!m_pologyStartedReceivingOutput) {
m_pologyStartedReceivingOutput = true;
}
static const QString BR = QStringLiteral("<br />");
m_pologyData += m_pologyProcess->readAllStandardError().replace('\n', BR);
m_pologyData += m_pologyProcess->readAllStandardError().replace('\n', MsgCtxtView::BR);
}
void MsgCtxtView::pologyHasFinished()
{
if (!m_pologyStartedReceivingOutput) {
m_pologyStartedReceivingOutput = true;
m_pologyData += i18nc("@info The pology command didn't return anything", "(empty)");
const QString grossPologyOutput = m_pologyProcess->readAllStandardOutput();
const QStringList pologyTmpLines = grossPologyOutput.split('\n', QString::SkipEmptyParts);
if (pologyTmpLines.count() == 0) {
m_pologyData += i18nc("@info The pology command didn't return anything", "(empty)");
} else {
foreach (const QString pologyTmp, pologyTmpLines) {
if (pologyTmp.startsWith(QStringLiteral("[note]")))
m_pologyData += pologyTmp;
}
}
}
if (!m_tempNotes.value(m_entry.entry).startsWith(QStringLiteral("Failed rules:"))) {
//This was not opened by pology
Expand All @@ -218,6 +228,7 @@ void MsgCtxtView::pologyHasFinished()
addTemporaryEntryNote(m_entry.entry, m_pologyData);
}
m_pologyProcess->deleteLater();
m_pologyProcessInProgress = false;
}

void MsgCtxtView::addNoteUI()
Expand Down
3 changes: 3 additions & 0 deletions src/msgctxtview.h
Expand Up @@ -72,6 +72,7 @@ private slots:
QStackedLayout* m_stackedLayout;

KProcess* m_pologyProcess;
bool m_pologyProcessInProgress = false;
bool m_pologyStartedReceivingOutput;
QString m_pologyData;

Expand All @@ -84,6 +85,8 @@ private slots:
bool m_hasErrorNotes;
DocPos m_entry;
DocPos m_prevEntry;

static const QString BR;
};


Expand Down
2 changes: 1 addition & 1 deletion src/project/prefs_project_pology.ui
Expand Up @@ -48,7 +48,7 @@
<item row="2" column="1">
<widget class="QLabel" name="textLabel3_0">
<property name="text">
<string comment="@label:textbox">Use the following placeholders in order to set-up the commands: %u is the entry number, %f is the file name.</string>
<string comment="@label:textbox">Use the following placeholders in order to set-up the commands: %u is the entry number, %f is the file name. For instance: python /home/translator/i18n/pology/scripts/posieve.py -u %u check_rules %f</string>
</property>
<property name="wordWrap">
<bool>true</bool>
Expand Down
4 changes: 3 additions & 1 deletion src/project/projectlocal.kcfg
Expand Up @@ -22,7 +22,9 @@
</entry>
</group>
<group name="Pology">
<entry name="PologyEnabled" type="Bool"></entry>
<entry name="PologyEnabled" type="Bool">
<default>false</default>
</entry>
<entry name="PologyCommandEntry" type="String"></entry>
</group>
</kcfg>

0 comments on commit a4e1034

Please sign in to comment.