mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
client/api: do a single info api call
Initial calls to api.fetchConfig() in quick succession would launch multiple requests. This should be implemented in Info tbh not outside of it.
This commit is contained in:
@ -5,9 +5,11 @@ const request = require("superagent");
|
||||
const events = require("./events.js");
|
||||
const progress = require("./util/progress.js");
|
||||
const uri = require("./util/uri.js");
|
||||
const Info = require("../models/info.js");
|
||||
|
||||
let fileTokens = {};
|
||||
let remoteConfig = null;
|
||||
let remoteConfigPromise = null;
|
||||
|
||||
class Api extends events.EventTarget {
|
||||
constructor() {
|
||||
@ -68,9 +70,13 @@ class Api extends events.EventTarget {
|
||||
|
||||
fetchConfig() {
|
||||
if (remoteConfig === null) {
|
||||
return this.get(uri.formatApiLink("info")).then((response) => {
|
||||
if (remoteConfigPromise !== null) {
|
||||
return Promise.resolve(remoteConfigPromise);
|
||||
}
|
||||
remoteConfigPromise = Info.get().then((response) => {
|
||||
remoteConfig = response.config;
|
||||
});
|
||||
return remoteConfigPromise;
|
||||
} else {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
const api = require("../api.js");
|
||||
const config = require("../config.js");
|
||||
const Info = require("../models/info.js");
|
||||
const topNavigation = require("../models/top_navigation.js");
|
||||
const HomeView = require("../views/home_view.js");
|
||||
|
||||
@ -20,7 +19,7 @@ class HomeController {
|
||||
isDevelopmentMode: config.environment == "development",
|
||||
});
|
||||
|
||||
Info.get().then(
|
||||
api.fetchConfig().then(
|
||||
(info) => {
|
||||
this._homeView.setStats({
|
||||
diskUsage: info.diskUsage,
|
||||
|
Reference in New Issue
Block a user