osdir.com

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GitHub] brooklyn-ui pull request #94: Composer recent and filters


Github user tbouron commented on a diff in the pull request:

    https://github.com/apache/brooklyn-ui/pull/94#discussion_r229266836
  
    --- Diff: ui-modules/blueprint-composer/app/components/providers/recently-used-service.provider.js ---
    @@ -0,0 +1,62 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +export function recentlyUsedServiceProvider() {
    +    return {
    +        $get: ['$log', function ($log) { return new RecentlyUsedService($log); }]
    +    }
    +}
    +
    +export const PREFIX = 'org.apache.brooklyn.composer.lastUsed:';
    +
    +function RecentlyUsedService($log) {
    +    let service = {};
    +    
    +    service.getId = (brooklynObject) => {
    +        if (typeof brooklynObject === 'string') return brooklynObject;
    +        return (brooklynObject.containingBundle || '?') + "::" + 
    +            (brooklynObject.symbolicName || '?') + ":" + (brooklynObject.version || '?');
    +    };
    +    
    +    service.markUsed = (item, when) => {
    +        let id = service.getId(item);
    +        if (when) {
    +            let old = service.getLastUsed(id);
    +            if (old > when) return;
    +        } else {
    +            when = Date.now();
    +        }
    +        sessionStorage.setItem(PREFIX+id, when);
    --- End diff --
    
    We did hit the maximum size on the earlier day of the composer while saving the generated icons. Now, I think it's the actual size of the `localStorage` (5MB if I recall correctly) but don't remember if there is a limit per item or in total.
    
    Nonetheless, we need to handle this because `sessionStorage.setItem()` will throw if there is no more space left.


---