Unverified Commit 9cd7f886 authored by mvdbeek's avatar mvdbeek
Browse files

Only serialize history if changed since last check

parent bee95f0c
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -143,12 +143,14 @@ export async function secureHistory(history) {
/**
 * Content Current History
 */
export async function getCurrentHistoryFromServer() {
export async function getCurrentHistoryFromServer(since) {
    const url = "history/current_history_json";
    const response = await axios.get(prependPath(url));
    const response = await axios.get(prependPath(url), { params: { since: since } });
    const props = doResponse(response);
    if (props) {
        return new History(props);
    }
}

export async function setCurrentHistoryOnServer(history_id) {
    const url = "history/set_as_current";
+5 −2
Original line number Diff line number Diff line
@@ -25,13 +25,16 @@ export async function watchHistoryOnce(store) {
    // "Reset" watchTimeout so we don't queue up watchHistory calls in rewatchHistory.
    watchTimeout = null;
    // get current history
    const history = await getCurrentHistoryFromServer();
    const historyId = history.id;
    const checkForUpdate = new Date();
    const history = await getCurrentHistoryFromServer(lastUpdateTime);
    store.commit("setLastCheckedTime", { checkForUpdate });
    if (!history) {
        return;
    }

    // continue if the history update time has changed
    if (!lastUpdateTime || lastUpdateTime < history.update_time) {
        const historyId = history.id;
        lastUpdateTime = history.update_time;
        // execute request to obtain recently changed items
        const params = {
+6 −1
Original line number Diff line number Diff line
import logging

from dateutil.parser import isoparse
from markupsafe import escape
from sqlalchemy import (
    false,
@@ -993,9 +994,13 @@ class HistoryController(BaseUIController, SharableMixin, UsesAnnotations, UsesIt

    @web.json
    @web.do_not_cache
    def current_history_json(self, trans):
    def current_history_json(self, trans, since=None):
        """Return the current user's current history in a serialized, dictionary form."""
        history = trans.get_history(most_recent=True, create=True)
        if since and history.update_time <= isoparse(since):
            # Should ideally be a 204 response, but would require changing web.json
            # This endpoint should either give way to a proper API or a SSE loop
            return
        return self.history_data(trans, history)

    @web.json