Unverified Commit ddd9b7d0 authored by Marius van den Beek's avatar Marius van den Beek Committed by GitHub
Browse files

Merge pull request #14347 from davelopez/22.05_optimize_loading_all_histories

[22.05] Avoid loading expensive properties for all histories
parents 35757bd6 398f7731
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@
            class="rounded-0 text-decoration-none"
            @click="onDashboard">
            <icon icon="database" />
            <span>{{ history.size | niceFileSize }}</span>
            <span>{{ historySize | niceFileSize }}</span>
        </b-button>
        <b-button-group>
            <b-button
@@ -19,10 +19,10 @@
                class="rounded-0 text-decoration-none"
                @click="setFilter('')">
                <span class="fa fa-map-marker" />
                <span>{{ history.contents_active.active }}</span>
                <span>{{ numItemsActive }}</span>
            </b-button>
            <b-button
                v-if="history.contents_active.deleted"
                v-if="numItemsDeleted"
                v-b-tooltip.hover
                title="Show deleted"
                variant="link"
@@ -30,10 +30,10 @@
                class="rounded-0 text-decoration-none"
                @click="setFilter('deleted:true')">
                <icon icon="trash" />
                <span>{{ history.contents_active.deleted }}</span>
                <span>{{ numItemsDeleted }}</span>
            </b-button>
            <b-button
                v-if="history.contents_active.hidden"
                v-if="numItemsHidden"
                v-b-tooltip.hover
                title="Show hidden"
                variant="link"
@@ -41,7 +41,7 @@
                class="rounded-0 text-decoration-none"
                @click="setFilter('visible:false')">
                <icon icon="eye-slash" />
                <span>{{ history.contents_active.hidden }}</span>
                <span>{{ numItemsHidden }}</span>
            </b-button>
            <b-button
                v-b-tooltip.hover
@@ -60,6 +60,7 @@
import { backboneRoute } from "components/plugins/legacyNavigation";
import prettyBytes from "pretty-bytes";
import { formatDistanceToNowStrict } from "date-fns";
import { usesDetailedHistoryMixin } from "./usesDetailedHistoryMixin.js";

export default {
    filters: {
@@ -67,6 +68,7 @@ export default {
            return prettyBytes(rawSize);
        },
    },
    mixins: [usesDetailedHistoryMixin],
    props: {
        history: { type: Object, required: true },
        lastChecked: { type: Date, default: null },
+6 −4
Original line number Diff line number Diff line
@@ -13,16 +13,16 @@
            <b-dropdown-text id="history-op-all-content">
                <span v-localize>With entire history...</span>
            </b-dropdown-text>
            <b-dropdown-item v-if="history.contents_active.active" data-description="copy datasets" @click="onCopy">
            <b-dropdown-item v-if="numItemsActive" data-description="copy datasets" @click="onCopy">
                <span v-localize>Copy Datasets</span>
            </b-dropdown-item>
            <b-dropdown-item v-if="history.contents_active.hidden" v-b-modal:show-all-hidden-content>
            <b-dropdown-item v-if="numItemsHidden" v-b-modal:show-all-hidden-content>
                <span v-localize>Unhide All Hidden Content</span>
            </b-dropdown-item>
            <b-dropdown-item v-if="history.contents_active.hidden" v-b-modal:delete-all-hidden-content>
            <b-dropdown-item v-if="numItemsHidden" v-b-modal:delete-all-hidden-content>
                <span v-localize>Delete All Hidden Content</span>
            </b-dropdown-item>
            <b-dropdown-item v-if="history.contents_active.deleted" v-b-modal:purge-all-deleted-content>
            <b-dropdown-item v-if="numItemsDeleted" v-b-modal:purge-all-deleted-content>
                <span v-localize>Purge All Deleted Content</span>
            </b-dropdown-item>
        </b-dropdown>
@@ -43,8 +43,10 @@
<script>
import { unhideAllHiddenContent, deleteAllHiddenContent, purgeAllDeletedContent } from "components/History/model/crud";
import { iframeRedirect } from "components/plugins/legacyNavigation";
import { usesDetailedHistoryMixin } from "../usesDetailedHistoryMixin.js";

export default {
    mixins: [usesDetailedHistoryMixin],
    props: {
        history: { type: Object, required: true },
    },
+24 −0
Original line number Diff line number Diff line
/**
 * VueJS mixin exposing extended properties for a history in a safe way.
 * If the values haven't been loaded yet the computed properties will return 0 instead of undefined.
 */
export const usesDetailedHistoryMixin = {
    computed: {
        /** The total size in bytes of the sum of all the items in this history. */
        historySize() {
            return this.history.size || 0;
        },
        /** The number of items currently active (usable). */
        numItemsActive() {
            return this.history.contents_active?.active || 0;
        },
        /** The number of items deleted and/or purged. */
        numItemsDeleted() {
            return this.history.contents_active?.deleted || 0;
        },
        /** The number of items hidden. */
        numItemsHidden() {
            return this.history.contents_active?.hidden || 0;
        },
    },
};
+9 −1
Original line number Diff line number Diff line
@@ -39,6 +39,14 @@ function formData(fields = {}) {
 */
const stdHistoryParams = {
    view: "summary",
};

/**
 * Extended history request parameters.
 * Retrieves additional details which are usually more "expensive".
 */
const extendedHistoryParams = {
    view: "summary",
    keys: "size,contents_active",
};

@@ -58,7 +66,7 @@ export async function getHistoryList() {
 */
export async function getHistoryById(id) {
    const path = `api/histories/${id}`;
    const response = await axios.get(prependPath(path), { params: stdHistoryParams });
    const response = await axios.get(prependPath(path), { params: extendedHistoryParams });
    const props = doResponse(response);
    return new History(props);
}