Replace cached method calls with @memoized_method

Bug #1248230 reported by Radomir Dopieralski
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Dashboard (Horizon)
Fix Released
Medium
Radomir Dopieralski

Bug Description

There is a certain pattern repeated all over openstack_dashboard for caching results of method calls. It looks something like this:

    def get_data(self):
        if not hasattr(self, "_data"):
            # Calculate data here.
            self._data = data
        return self._data

This repeating pattern is an example of copy-and-paste programming and can be instead easily abstracted away into a decorator. This way all the logic is in one place and all the code benefits from bugfixes and performance improvement of that code.

Changed in horizon:
assignee: nobody → Radomir Dopieralski (thesheep)
Changed in horizon:
status: New → In Progress
Revision history for this message
Ladislav Smola (lsmola) wrote :

Yeah, this one is ugly. Thanks for picking this up.

Matthias Runge (mrunge)
Changed in horizon:
milestone: none → icehouse-2
importance: Undecided → Medium
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to horizon (master)

Reviewed: https://review.openstack.org/54094
Committed: https://git.openstack.org/cgit/openstack/horizon/commit/?id=b7537a8b8155fcf112067eb7d9d12339e280e44f
Submitter: Jenkins
Branch: master

commit b7537a8b8155fcf112067eb7d9d12339e280e44f
Author: Radomir Dopieralski <email address hidden>
Date: Mon Oct 28 11:24:00 2013 +0100

    Use memoized_method decorator in views

    A lot of horizon's views use the pattern:

        def get_data(self):
            if not hasattr(self, "_data"):
                # Calculate data here.
                self._data = data
            return self._data

    This is copy-pasted all over the codebase. It's better to handle that
    with a single decorator. In the future, we might even replace it with
    some better caching approach.

    Closes-bug: #1248230
    Change-Id: Id021fccf9032e5068993ec91a7774a5d0fbf29bb

Changed in horizon:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in horizon:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in horizon:
milestone: icehouse-2 → 2014.1
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.