bf67d0e650541232bbaa66aa459fbbd9bf1a5cd4,homeassistant/components/recorder/purge.py,,purge_old_data,#Any#Any#,12

Before Change


        // updated in a long time
        states_alias = orm.aliased(States, name="StatesAlias")
        protected_states = session.query(States.state_id, States.event_id)\
            .filter(~exists()
                    .where(States.entity_id ==
                           states_alias.entity_id)
                    .where(states_alias.last_updated >
                           States.last_updated))\
            .all()

After Change


        // For each entity, the most recent state is protected from deletion
        // s.t. we can properly restore state even if the entity has not been
        // updated in a long time
        protected_states = session.query(func.max(States.state_id)) \
            .group_by(States.entity_id).all()

        protected_state_ids = tuple((state[0] for state in protected_states))

        deleted_rows = session.query(States) \
                              .filter((States.last_updated < purge_before)) \
                              .filter(~States.state_id.in_(
                                  protected_state_ids)) \
                              .delete(synchronize_session=False)
        _LOGGER.debug("Deleted %s states", deleted_rows)

        // We also need to protect the events belonging to the protected states.
        // Otherwise, if the SQL server has "ON DELETE CASCADE" as default, it
        // will delete the protected state when deleting its associated
        // event. Also, we would be producing NULLed foreign keys otherwise.
        protected_events = session.query(States.event_id) \
            .filter(States.state_id.in_(protected_state_ids)) \
            .filter(States.event_id.isnot(None)) \
            .all()

        protected_event_ids = tuple((state[0] for state in protected_events))

        deleted_rows = session.query(Events) \
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 4

Instances


Project Name: home-assistant/home-assistant
Commit Name: bf67d0e650541232bbaa66aa459fbbd9bf1a5cd4
Time: 2018-02-17
Author: amelchio@nogoto.net
File Name: homeassistant/components/recorder/purge.py
Class Name:
Method Name: purge_old_data


Project Name: home-assistant/home-assistant
Commit Name: 0e2d98dbf56c7476b44953e383d80cd066d5c9e1
Time: 2018-02-15
Author: amelchio@nogoto.net
File Name: homeassistant/components/recorder/purge.py
Class Name:
Method Name: purge_old_data


Project Name: raghakot/keras-vis
Commit Name: 599dcf091385cfda00d62d8c1e631f1a6b0c2c67
Time: 2017-05-16
Author: ragha@outlook.com
File Name: vis/visualization.py
Class Name:
Method Name: visualize_cam