mirror of https://github.com/micromata/borgbackup-butler.git

Kai Reinhard
16.20.2018 47b27687ea1e77e7d6ae26eb0e47ab85e90c5d50
Lazy loading of repos.
3 files modified
56 ■■■■ changed files
borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ButlerCache.java 12 ●●●● patch | view | raw | blame | history
borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ReposRest.java 38 ●●●●● patch | view | raw | blame | history
borgbutler-webapp/src/components/views/repos/RepoListView.jsx 6 ●●●● patch | view | raw | blame | history
borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ButlerCache.java
@@ -26,6 +26,7 @@
    private JCSCache jcsCache;
    private CacheAccess<String, Repository> repoCacheAccess;
    private ArchiveFilelistCache archiveFilelistCache;
    private int notYetLoadedIdCounter = 1;
    public static ButlerCache getInstance() {
        return instance;
@@ -81,9 +82,16 @@
    public List<Repository> getAllRepositories() {
        List<Repository> repositories = new ArrayList<>();
        for (BorgRepoConfig repoConfig : ConfigurationHandler.getConfiguration().getRepoConfigs()) {
            Repository repository = getRepository(repoConfig);
            Repository repository = repoCacheAccess.get(repoConfig.getRepo());
            if (repository == null) {
                continue;
                if (repoConfig.getId() == null) {
                    // Temporary id:
                    repoConfig.setId("not_yet_loaded_" + notYetLoadedIdCounter++);
                }
                repository = new Repository()
                        .setDisplayName(repoConfig.getDisplayName())
                        .setName(repoConfig.getRepo())
                        .setId(repoConfig.getId());
            }
            repositories.add(repository);
        }
borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ReposRest.java
@@ -21,6 +21,23 @@
    private static Logger log = LoggerFactory.getLogger(ReposRest.class);
    @GET
    @Path("list")
    @Produces(MediaType.APPLICATION_JSON)
    /**
     *
     * @param prettyPrinter If true then the json output will be in pretty format.
     * @return A list of repositories of type {@link BorgRepository}.
     * @see JsonUtils#toJson(Object, boolean)
     */
    public String getList(@QueryParam("prettyPrinter") boolean prettyPrinter) {
        List<Repository> repositories = ButlerCache.getInstance().getAllRepositories();
        if (CollectionUtils.isEmpty(repositories)) {
            return "";
        }
        return JsonUtils.toJson(repositories, prettyPrinter);
    }
    @GET
    @Path("repo")
    @Produces(MediaType.APPLICATION_JSON)
    /**
@@ -72,25 +89,4 @@
        Archive archive = ButlerCache.getInstance().getArchive(repoName, archiveIdOrName, force);
        return JsonUtils.toJson(archive, prettyPrinter);
    }
    @GET
    @Path("list")
    @Produces(MediaType.APPLICATION_JSON)
    /**
     *
     * @param force If true, a reload of all repositories is forced.
     * @param prettyPrinter If true then the json output will be in pretty format.
     * @return A list of repositories of type {@link BorgRepository}.
     * @see JsonUtils#toJson(Object, boolean)
     */
    public String getList(@QueryParam("force") boolean force, @QueryParam("prettyPrinter") boolean prettyPrinter) {
        if (force) {
            ButlerCache.getInstance().clearRepoCacheAccess();
        }
        List<Repository> repositories = ButlerCache.getInstance().getAllRepositories();
        if (CollectionUtils.isEmpty(repositories)) {
            return "";
        }
        return JsonUtils.toJson(repositories, prettyPrinter);
    }
}
borgbutler-webapp/src/components/views/repos/RepoListView.jsx
@@ -19,13 +19,13 @@
        this.fetchRepos();
    };
    fetchRepos = (force) => {
    fetchRepos = () => {
        this.setState({
            isFetching: true,
            failed: false,
            repos: undefined
        });
        fetch(`${this.path}/list?force=${force}`, {
        fetch(`${this.path}/list`, {
            method: 'GET',
            headers: {
                'Accept': 'application/json'
@@ -83,7 +83,7 @@
                Repositories
                <div
                    className={'btn btn-outline-primary refresh-button-right'}
                    onClick={this.fetchRepos.bind(this, true)}
                    onClick={this.fetchRepos.bind(this)}
                >
                    <IconRefresh/>
                </div>