Warning: session_start(): open(/var/lib/php/sessions/sess_unmqcj1cjeimm9c7rcj5fs8h8b, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
sclass Google extends DynModule {
S query;
L result;
transient Q q;
transient int maxInputLength = 120;
transient NotTooOften notTooOften = onlyEvery10Secs();
transient WaitForStableValue waitForStableValue = new(5.0);
transient volatile bool calculating;
transient JTable table;
transient ReliableSingleThread rst;
JComponent visualize() { ret dataToTable_uneditable(result, table = sexyTable()); }
void unvisualize2() { table = null; }
void start {
q = startQ();
doEvery(1000, r update);
}
svoid update {
lock programLock();
S s = dm_getInterestingString();
if (nempty(s) && l(s) <= maxInputLength) { // TODO: more quality checks?
waitForStableValue.set(s);
}
fS q = waitForStableValue!;
if (nempty(q) && neq(q, query) && allowedToGoogleSomething())
this.q.add(r { calc(q) });
}
void calc(S q) {
if (eq(query, q)) ret;
query = q; result = null;
calculating = true;
try {
L> l = quickGoogle2(q);
result = map(l, func(T3 t) -> SS {
litorderedmap("Result" := second(t), "Desc" := third(t), "Link" := first(t))
});
JTable t = table;
if (t != null)
dataToTable_uneditable(result, t);
} finally {
calculating = false;
}
}
bool allowedToGoogleSomething() {
ret notTooOften.canDoAgain_willDoIfTrue();
}
}