[vlc-devel] [PATCH 06/13] qt: medialib: use list cache from MLBaseModel

Pierre Lamot pierre at videolabs.io
Tue Nov 24 10:15:05 CET 2020


Hi

> -    mutable std::vector<std::unique_ptr<T>> m_item_list;
> -    mutable bool m_initialized;
> -    mutable size_t m_total_count;
> -    mutable size_t m_offset; /* offset of m_item_list in the global 
> list */
> +    /* Data loader for the cache */
> +    struct Loader : public ListCacheLoader<std::unique_ptr<T>>
> +    {
> +        Loader(const MLSlidingWindowModel &model)
> +            : m_model(model)
> +            , m_searchPattern(model.m_search_pattern)
> +            , m_sort(model.m_sort)
> +            , m_sort_desc(model.m_sort_desc)

Do you need to keep copy each criteria here? can't you use them directly 
from the m_model upon which you keep a reference. I would expect the 
cache to be invalidated when they changes in the Model.
That being said, this probably makes sense once your request is ran in a 
separate thread.

> +        {
> +        }
> +
> +        size_t count() const override;
> +        std::vector<std::unique_ptr<T>> load(size_t index, size_t
> count) const override;
> +
> +    private:
> +        const MLSlidingWindowModel &m_model;
> +        QString m_searchPattern;
> +        vlc_ml_sorting_criteria_t m_sort;
> +        bool m_sort_desc;
> +    };
> +
> +    mutable std::unique_ptr<ListCache<std::unique_ptr<T>>> m_cache;
>  };
> 
> +template <typename T>
> +size_t MLSlidingWindowModel<T>::Loader::count() const
> +{
> +    MLQueryParams params{ m_searchPattern.toUtf8(), m_sort, 
> m_sort_desc };
> +    return m_model.countTotalElements(params);
> +}
> +
> +template <typename T>
> +std::vector<std::unique_ptr<T>>
> +MLSlidingWindowModel<T>::Loader::load(size_t index, size_t count) 
> const
> +{
> +    MLQueryParams params{ m_searchPattern.toUtf8(), m_sort,
> m_sort_desc, index, count };
> +    return m_model.fetch(params);
> +}
> +
>  #endif // MLBASEMODEL_HPP


More information about the vlc-devel mailing list