import calendar
import datetime
from unittest import TestCase

import pytz
from dateutil.parser import parse as date_parse
from tests import BaseTestCase

from redash import models, redis_connection
from redash.models import db, types
from redash.utils import gen_query_hash, utcnow


class DashboardTest(BaseTestCase):
    def test_appends_suffix_to_slug_when_duplicate(self):
        d1 = self.factory.create_dashboard()
        db.session.flush()
        self.assertEqual(d1.slug, 'test')

        d2 = self.factory.create_dashboard(user=d1.user)
        db.session.flush()
        self.assertNotEqual(d1.slug, d2.slug)

        d3 = self.factory.create_dashboard(user=d1.user)
        db.session.flush()
        self.assertNotEqual(d1.slug, d3.slug)
        self.assertNotEqual(d2.slug, d3.slug)


class ShouldScheduleNextTest(TestCase):
    def test_interval_schedule_that_needs_reschedule(self):
        now = utcnow()
        two_hours_ago = now - datetime.timedelta(hours=2)
        self.assertTrue(models.should_schedule_next(two_hours_ago, now, "3600"))

    def test_interval_schedule_that_doesnt_need_reschedule(self):
        now = utcnow()
        half_an_hour_ago = now - datetime.timedelta(minutes=30)
        self.assertFalse(models.should_schedule_next(half_an_hour_ago, now, "3600"))

    def test_exact_time_that_needs_reschedule(self):
        now = utcnow()
        yesterday = now - datetime.timedelta(days=1)
        scheduled_datetime = now - datetime.timedelta(hours=3)
        scheduled_time = "{:02d}:00".format(scheduled_datetime.hour)
        self.assertTrue(models.should_schedule_next(yesterday, now, "86400",
                                                    scheduled_time))

    def test_exact_time_that_doesnt_need_reschedule(self):
        now = date_parse("2015-10-16 20:10")
        yesterday = date_parse("2015-10-15 23:07")
        schedule = "23:00"
        self.assertFalse(models.should_schedule_next(yesterday, now, "86400", schedule))

    def test_exact_time_with_day_change(self):
        now = utcnow().replace(hour=0, minute=1)
        previous = (now - datetime.timedelta(days=2)).replace(hour=23,
                                                              minute=59)
        schedule = "23:59".format(now.hour + 3)
        self.assertTrue(models.should_schedule_next(previous, now, "86400", schedule))

    def test_exact_time_every_x_days_that_needs_reschedule(self):
        now = utcnow()
        four_days_ago = now - datetime.timedelta(days=4)
        three_day_interval = "259200"
        scheduled_datetime = now - datetime.timedelta(hours=3)
        scheduled_time = "{:02d}:00".format(scheduled_datetime.hour)
        self.assertTrue(models.should_schedule_next(four_days_ago, now, three_day_interval,
                                                    scheduled_time))

    def test_exact_time_every_x_days_that_doesnt_need_reschedule(self):
        now = utcnow()
        four_days_ago = now - datetime.timedelta(days=2)
        three_day_interval = "259200"
        scheduled_datetime = now - datetime.timedelta(hours=3)
        scheduled_time = "{:02d}:00".format(scheduled_datetime.hour)
        self.assertFalse(models.should_schedule_next(four_days_ago, now, three_day_interval,
                                                    scheduled_time))

    def test_exact_time_every_x_days_with_day_change(self):
        now = utcnow().replace(hour=23, minute=59)
        previous = (now - datetime.timedelta(days=2)).replace(hour=0, minute=1)
        schedule = "23:58"
        three_day_interval = "259200"
        self.assertTrue(models.should_schedule_next(previous, now, three_day_interval, schedule))

    def test_exact_time_every_x_weeks_that_needs_reschedule(self):
        # Setup:
        #
        # 1) The query should run every 3 weeks on Tuesday
        # 2) The last time it ran was 3 weeks ago from this week's Thursday
        # 3) It is now Wednesday of this week
        #
        # Expectation: Even though less than 3 weeks have passed since the
        #              last run 3 weeks ago on Thursday, it's overdue since
        #              it should be running on Tuesdays.
        this_thursday = utcnow() + datetime.timedelta(days=list(calendar.day_name).index("Thursday") - utcnow().weekday())
        three_weeks_ago = this_thursday - datetime.timedelta(weeks=3)
        now = this_thursday - datetime.timedelta(days=1)
        three_week_interval = "1814400"
        scheduled_datetime = now - datetime.timedelta(hours=3)
        scheduled_time = "{:02d}:00".format(scheduled_datetime.hour)
        self.assertTrue(models.should_schedule_next(three_weeks_ago, now, three_week_interval,
                                                    scheduled_time, "Tuesday"))

    def test_exact_time_every_x_weeks_that_doesnt_need_reschedule(self):
        # Setup:
        #
        # 1) The query should run every 3 weeks on Thurday
        # 2) The last time it ran was 3 weeks ago from this week's Tuesday
        # 3) It is now Wednesday of this week
        #
        # Expectation: Even though more than 3 weeks have passed since the
        #              last run 3 weeks ago on Tuesday, it's not overdue since
        #              it should be running on Thursdays.
        this_tuesday = utcnow() + datetime.timedelta(days=list(calendar.day_name).index("Tuesday") - utcnow().weekday())
        three_weeks_ago = this_tuesday - datetime.timedelta(weeks=3)
        now = this_tuesday + datetime.timedelta(days=1)
        three_week_interval = "1814400"
        scheduled_datetime = now - datetime.timedelta(hours=3)
        scheduled_time = "{:02d}:00".format(scheduled_datetime.hour)
        self.assertFalse(models.should_schedule_next(three_weeks_ago, now, three_week_interval,
                                                    scheduled_time, "Thursday"))

    def test_backoff(self):
        now = utcnow()
        two_hours_ago = now - datetime.timedelta(hours=2)
        self.assertTrue(models.should_schedule_next(two_hours_ago, now, "3600",
                                                    failures=5))
        self.assertFalse(models.should_schedule_next(two_hours_ago, now,
                                                     "3600", failures=10))

    def test_next_iteration_overflow(self):
        now = utcnow()
        two_hours_ago = now - datetime.timedelta(hours=2)
        self.assertFalse(models.should_schedule_next(two_hours_ago, now, "3600", failures=32))


class QueryOutdatedQueriesTest(BaseTestCase):
    # TODO: this test can be refactored to use mock version of should_schedule_next to simplify it.
    def test_outdated_queries_skips_unscheduled_queries(self):
        query = self.factory.create_query(schedule={'interval':None, 'time': None, 'until':None, 'day_of_week':None})
        query_with_none = self.factory.create_query(schedule=None)

        queries = models.Query.outdated_queries()

        self.assertNotIn(query, queries)
        self.assertNotIn(query_with_none, queries)

    def test_outdated_queries_works_with_ttl_based_schedule(self):
        two_hours_ago = utcnow() - datetime.timedelta(hours=2)
        query = self.factory.create_query(schedule={'interval':'3600', 'time': None, 'until':None, 'day_of_week':None})
        query_result = self.factory.create_query_result(query=query.query_text, retrieved_at=two_hours_ago)
        query.latest_query_data = query_result

        queries = models.Query.outdated_queries()
        self.assertIn(query, queries)

    def test_outdated_queries_works_scheduled_queries_tracker(self):
        two_hours_ago = utcnow() - datetime.timedelta(hours=2)
        query = self.factory.create_query(schedule={'interval':'3600', 'time': None, 'until':None, 'day_of_week':None})
        query_result = self.factory.create_query_result(query=query, retrieved_at=two_hours_ago)
        query.latest_query_data = query_result

        models.scheduled_queries_executions.update(query.id)

        queries = models.Query.outdated_queries()
        self.assertNotIn(query, queries)

    def test_skips_fresh_queries(self):
        half_an_hour_ago = utcnow() - datetime.timedelta(minutes=30)
        query = self.factory.create_query(schedule={'interval':'3600', 'time': None, 'until':None, 'day_of_week':None})
        query_result = self.factory.create_query_result(query=query.query_text, retrieved_at=half_an_hour_ago)
        query.latest_query_data = query_result

        queries = models.Query.outdated_queries()
        self.assertNotIn(query, queries)

    def test_outdated_queries_works_with_specific_time_schedule(self):
        half_an_hour_ago = utcnow() - datetime.timedelta(minutes=30)
        query = self.factory.create_query(schedule={'interval':'86400', 'time':half_an_hour_ago.strftime('%H:%M'), 'until':None, 'day_of_week':None})
        query_result = self.factory.create_query_result(query=query.query_text, retrieved_at=half_an_hour_ago - datetime.timedelta(days=1))
        query.latest_query_data = query_result

        queries = models.Query.outdated_queries()
        self.assertIn(query, queries)

    def test_enqueues_query_only_once(self):
        """
        Only one query per data source with the same text will be reported by
        Query.outdated_queries().
        """
        query = self.factory.create_query(schedule={'interval':'60', 'until':None, 'time': None, 'day_of_week':None})
        query2 = self.factory.create_query(
            schedule={'interval':'60', 'until':None, 'time': None, 'day_of_week':None}, query_text=query.query_text,
            query_hash=query.query_hash)
        retrieved_at = utcnow() - datetime.timedelta(minutes=10)
        query_result = self.factory.create_query_result(
            retrieved_at=retrieved_at, query_text=query.query_text,
            query_hash=query.query_hash)
        query.latest_query_data = query_result
        query2.latest_query_data = query_result

        self.assertEqual(list(models.Query.outdated_queries()), [query2])

    def test_enqueues_query_with_correct_data_source(self):
        """
        Queries from different data sources will be reported by
        Query.outdated_queries() even if they have the same query text.
        """
        query = self.factory.create_query(
            schedule={'interval':'60', 'until':None, 'time': None, 'day_of_week':None}, data_source=self.factory.create_data_source())
        query2 = self.factory.create_query(
            schedule={'interval':'60', 'until':None, 'time': None, 'day_of_week':None}, query_text=query.query_text,
            query_hash=query.query_hash)
        retrieved_at = utcnow() - datetime.timedelta(minutes=10)
        query_result = self.factory.create_query_result(
            retrieved_at=retrieved_at, query_text=query.query_text,
            query_hash=query.query_hash)
        query.latest_query_data = query_result
        query2.latest_query_data = query_result

        outdated_queries = models.Query.outdated_queries()
        self.assertEqual(len(outdated_queries), 2)
        self.assertIn(query, outdated_queries)
        self.assertIn(query2, outdated_queries)

    def test_enqueues_only_for_relevant_data_source(self):
        """
        If multiple queries with the same text exist, only ones that are
        scheduled to be refreshed are reported by Query.outdated_queries().
        """
        query = self.factory.create_query(schedule={'interval':'60', 'until':None, 'time': None, 'day_of_week':None})
        query2 = self.factory.create_query(
            schedule={'interval':'3600', 'until':None, 'time': None, 'day_of_week':None}, query_text=query.query_text,
            query_hash=query.query_hash)
        retrieved_at = utcnow() - datetime.timedelta(minutes=10)
        query_result = self.factory.create_query_result(
            retrieved_at=retrieved_at, query_text=query.query_text,
            query_hash=query.query_hash)
        query.latest_query_data = query_result
        query2.latest_query_data = query_result

        self.assertEqual(list(models.Query.outdated_queries()), [query])

    def test_failure_extends_schedule(self):
        """
        Execution failures recorded for a query result in exponential backoff
        for scheduling future execution.
        """
        query = self.factory.create_query(schedule={'interval':'60', 'until':None, 'time': None, 'day_of_week':None}, schedule_failures=4)
        retrieved_at = utcnow() - datetime.timedelta(minutes=16)
        query_result = self.factory.create_query_result(
            retrieved_at=retrieved_at, query_text=query.query_text,
            query_hash=query.query_hash)
        query.latest_query_data = query_result

        self.assertEqual(list(models.Query.outdated_queries()), [])

        query_result.retrieved_at = utcnow() - datetime.timedelta(minutes=17)
        self.assertEqual(list(models.Query.outdated_queries()), [query])

    def test_schedule_until_after(self):
        """
        Queries with non-null ``schedule['until']`` are not reported by
        Query.outdated_queries() after the given time is past.
        """
        one_day_ago = (utcnow() - datetime.timedelta(days=1)).strftime("%Y-%m-%d")
        two_hours_ago = utcnow() - datetime.timedelta(hours=2)
        query = self.factory.create_query(schedule={'interval':'3600', 'until':one_day_ago, 'time':None, 'day_of_week':None})
        query_result = self.factory.create_query_result(query=query.query_text, retrieved_at=two_hours_ago)
        query.latest_query_data = query_result

        queries = models.Query.outdated_queries()
        self.assertNotIn(query, queries)

    def test_schedule_until_before(self):
        """
        Queries with non-null ``schedule['until']`` are reported by
        Query.outdated_queries() before the given time is past.
        """
        one_day_from_now = (utcnow() + datetime.timedelta(days=1)).strftime("%Y-%m-%d")
        two_hours_ago = utcnow() - datetime.timedelta(hours=2)
        query = self.factory.create_query(schedule={'interval':'3600', 'until':one_day_from_now, 'time': None, 'day_of_week':None})
        query_result = self.factory.create_query_result(query=query.query_text, retrieved_at=two_hours_ago)
        query.latest_query_data = query_result

        queries = models.Query.outdated_queries()
        self.assertIn(query, queries)


class QueryArchiveTest(BaseTestCase):
    def test_archive_query_sets_flag(self):
        query = self.factory.create_query()
        db.session.flush()
        query.archive()

        self.assertEqual(query.is_archived, True)

    def test_archived_query_doesnt_return_in_all(self):
        query = self.factory.create_query(schedule={'interval':'1', 'until':None, 'time': None, 'day_of_week':None})
        yesterday = utcnow() - datetime.timedelta(days=1)
        query_result = models.QueryResult.store_result(
            query.org_id, query.data_source, query.query_hash, query.query_text,
            "1", 123, yesterday)

        query.latest_query_data = query_result
        groups = list(models.Group.query.filter(models.Group.id.in_(query.groups)))
        self.assertIn(query, list(models.Query.all_queries([g.id for g in groups])))
        self.assertIn(query, models.Query.outdated_queries())
        db.session.flush()
        query.archive()

        self.assertNotIn(query, list(models.Query.all_queries([g.id for g in groups])))
        self.assertNotIn(query, models.Query.outdated_queries())

    def test_removes_associated_widgets_from_dashboards(self):
        widget = self.factory.create_widget()
        query = widget.visualization.query_rel
        db.session.commit()
        query.archive()
        db.session.flush()
        self.assertEqual(models.Widget.query.get(widget.id), None)

    def test_removes_scheduling(self):
        query = self.factory.create_query(schedule={'interval':'1', 'until':None, 'time': None, 'day_of_week':None})

        query.archive()

        self.assertIsNone(query.schedule)

    def test_deletes_alerts(self):
        subscription = self.factory.create_alert_subscription()
        query = subscription.alert.query_rel
        db.session.commit()
        query.archive()
        db.session.flush()
        self.assertEqual(models.Alert.query.get(subscription.alert.id), None)
        self.assertEqual(models.AlertSubscription.query.get(subscription.id), None)


class TestUnusedQueryResults(BaseTestCase):
    def test_returns_only_unused_query_results(self):
        two_weeks_ago = utcnow() - datetime.timedelta(days=14)
        qr = self.factory.create_query_result()
        self.factory.create_query(latest_query_data=qr)
        db.session.flush()
        unused_qr = self.factory.create_query_result(retrieved_at=two_weeks_ago)
        self.assertIn(unused_qr, list(models.QueryResult.unused()))
        self.assertNotIn(qr, list(models.QueryResult.unused()))

    def test_returns_only_over_a_week_old_results(self):
        two_weeks_ago = utcnow() - datetime.timedelta(days=14)
        unused_qr = self.factory.create_query_result(retrieved_at=two_weeks_ago)
        db.session.flush()
        new_unused_qr = self.factory.create_query_result()

        self.assertIn(unused_qr, list(models.QueryResult.unused()))
        self.assertNotIn(new_unused_qr, list(models.QueryResult.unused()))


class TestQueryAll(BaseTestCase):
    def test_returns_only_queries_in_given_groups(self):
        ds1 = self.factory.create_data_source()
        ds2 = self.factory.create_data_source()

        group1 = models.Group(name="g1", org=ds1.org, permissions=['create', 'view'])
        group2 = models.Group(name="g2", org=ds1.org, permissions=['create', 'view'])

        q1 = self.factory.create_query(data_source=ds1)
        q2 = self.factory.create_query(data_source=ds2)

        db.session.add_all([
            ds1, ds2,
            group1, group2,
            q1, q2,
            models.DataSourceGroup(
                group=group1, data_source=ds1),
            models.DataSourceGroup(group=group2, data_source=ds2)
            ])
        db.session.flush()
        self.assertIn(q1, list(models.Query.all_queries([group1.id])))
        self.assertNotIn(q2, list(models.Query.all_queries([group1.id])))
        self.assertIn(q1, list(models.Query.all_queries([group1.id, group2.id])))
        self.assertIn(q2, list(models.Query.all_queries([group1.id, group2.id])))

    def test_skips_drafts(self):
        q = self.factory.create_query(is_draft=True)
        self.assertNotIn(q, models.Query.all_queries([self.factory.default_group.id]))

    def test_includes_drafts_of_given_user(self):
        q = self.factory.create_query(is_draft=True)
        self.assertIn(q, models.Query.all_queries([self.factory.default_group.id], user_id=q.user_id))

    def test_order_by_relationship(self):
        u1 = self.factory.create_user(name='alice')
        u2 = self.factory.create_user(name='bob')
        self.factory.create_query(user=u1)
        self.factory.create_query(user=u2)
        db.session.commit()
        # have to reset the order here with None since all_queries orders by
        # created_at by default
        base = models.Query.all_queries([self.factory.default_group.id]).order_by(None)
        qs1 = base.order_by(models.User.name)
        self.assertEqual(['alice', 'bob'], [q.user.name for q in qs1])
        qs2 = base.order_by(models.User.name.desc())
        self.assertEqual(['bob', 'alice'], [q.user.name for q in qs2])


class TestGroup(BaseTestCase):
    def test_returns_groups_with_specified_names(self):
        org1 = self.factory.create_org()
        org2 = self.factory.create_org()

        matching_group1 = models.Group(id=999, name="g1", org=org1)
        matching_group2 = models.Group(id=888, name="g2", org=org1)
        non_matching_group = models.Group(id=777, name="g1", org=org2)

        groups = models.Group.find_by_name(org1, ["g1", "g2"])
        self.assertIn(matching_group1, groups)
        self.assertIn(matching_group2, groups)
        self.assertNotIn(non_matching_group, groups)

    def test_returns_no_groups(self):
        org1 = self.factory.create_org()

        models.Group(id=999, name="g1", org=org1)
        self.assertEqual([], models.Group.find_by_name(org1, ["non-existing"]))


class TestQueryResultStoreResult(BaseTestCase):
    def setUp(self):
        super(TestQueryResultStoreResult, self).setUp()
        self.data_source = self.factory.data_source
        self.query = "SELECT 1"
        self.query_hash = gen_query_hash(self.query)
        self.runtime = 123
        self.utcnow = utcnow()
        self.data = '{"a": 1}'

    def test_stores_the_result(self):
        query_result = models.QueryResult.store_result(
            self.data_source.org_id, self.data_source, self.query_hash,
            self.query, self.data, self.runtime, self.utcnow)

        self.assertEqual(query_result._data, self.data)
        self.assertEqual(query_result.runtime, self.runtime)
        self.assertEqual(query_result.retrieved_at, self.utcnow)
        self.assertEqual(query_result.query_text, self.query)
        self.assertEqual(query_result.query_hash, self.query_hash)
        self.assertEqual(query_result.data_source, self.data_source)


class TestEvents(BaseTestCase):
    def raw_event(self):
        timestamp = 1411778709.791
        user = self.factory.user
        created_at = datetime.datetime.utcfromtimestamp(timestamp)
        db.session.flush()
        raw_event = {"action": "view",
                      "timestamp": timestamp,
                      "object_type": "dashboard",
                      "user_id": user.id,
                      "object_id": 1,
                      "org_id": 1}

        return raw_event, user, created_at

    def test_records_event(self):
        raw_event, user, created_at = self.raw_event()

        event = models.Event.record(raw_event)
        db.session.flush()
        self.assertEqual(event.user, user)
        self.assertEqual(event.action, "view")
        self.assertEqual(event.object_type, "dashboard")
        self.assertEqual(event.object_id, 1)
        self.assertEqual(event.created_at, created_at)

    def test_records_additional_properties(self):
        raw_event, _, _ = self.raw_event()
        additional_properties = {'test': 1, 'test2': 2, 'whatever': "abc"}
        raw_event.update(additional_properties)

        event = models.Event.record(raw_event)

        self.assertDictEqual(event.additional_properties, additional_properties)


def _set_up_dashboard_test(d):
    d.g1 = d.factory.create_group(name='First', permissions=['create', 'view'])
    d.g2 = d.factory.create_group(name='Second',  permissions=['create', 'view'])
    d.ds1 = d.factory.create_data_source()
    d.ds2 = d.factory.create_data_source()
    db.session.flush()
    d.u1 = d.factory.create_user(group_ids=[d.g1.id])
    d.u2 = d.factory.create_user(group_ids=[d.g2.id])
    db.session.add_all([
        models.DataSourceGroup(group=d.g1, data_source=d.ds1),
        models.DataSourceGroup(group=d.g2, data_source=d.ds2)
    ])
    d.q1 = d.factory.create_query(data_source=d.ds1)
    d.q2 = d.factory.create_query(data_source=d.ds2)
    d.v1 = d.factory.create_visualization(query_rel=d.q1)
    d.v2 = d.factory.create_visualization(query_rel=d.q2)
    d.w1 = d.factory.create_widget(visualization=d.v1)
    d.w2 = d.factory.create_widget(visualization=d.v2)
    d.w3 = d.factory.create_widget(visualization=d.v2, dashboard=d.w2.dashboard)
    d.w4 = d.factory.create_widget(visualization=d.v2)
    d.w5 = d.factory.create_widget(visualization=d.v1, dashboard=d.w4.dashboard)
    d.w1.dashboard.is_draft = False
    d.w2.dashboard.is_draft = False
    d.w4.dashboard.is_draft = False


class TestDashboardAll(BaseTestCase):
    def setUp(self):
        super(TestDashboardAll, self).setUp()
        _set_up_dashboard_test(self)

    def test_requires_group_or_user_id(self):
        d1 = self.factory.create_dashboard()
        self.assertNotIn(d1, list(models.Dashboard.all(
           d1.user.org, d1.user.group_ids, None)))
        l2 = list(models.Dashboard.all(
            d1.user.org, [0], d1.user.id))
        self.assertIn(d1, l2)

    def test_returns_dashboards_based_on_groups(self):
        self.assertIn(self.w1.dashboard, list(models.Dashboard.all(
            self.u1.org, self.u1.group_ids, None)))
        self.assertIn(self.w2.dashboard, list(models.Dashboard.all(
            self.u2.org, self.u2.group_ids, None)))
        self.assertNotIn(self.w1.dashboard, list(models.Dashboard.all(
            self.u2.org, self.u2.group_ids, None)))
        self.assertNotIn(self.w2.dashboard, list(models.Dashboard.all(
            self.u1.org, self.u1.group_ids, None)))

    def test_returns_each_dashboard_once(self):
        dashboards = list(models.Dashboard.all(self.u2.org, self.u2.group_ids, None))
        self.assertEqual(len(dashboards), 2)

    def test_returns_dashboard_you_have_partial_access_to(self):
        self.assertIn(self.w5.dashboard, models.Dashboard.all(self.u1.org, self.u1.group_ids, None))

    def test_returns_dashboards_created_by_user(self):
        d1 = self.factory.create_dashboard(user=self.u1)
        db.session.flush()
        self.assertIn(d1, list(models.Dashboard.all(self.u1.org, self.u1.group_ids, self.u1.id)))
        self.assertIn(d1, list(models.Dashboard.all(self.u1.org, [0], self.u1.id)))
        self.assertNotIn(d1, list(models.Dashboard.all(self.u2.org, self.u2.group_ids, self.u2.id)))

    def test_returns_dashboards_with_text_widgets(self):
        w1 = self.factory.create_widget(visualization=None)

        self.assertIn(w1.dashboard, models.Dashboard.all(self.u1.org, self.u1.group_ids, None))
        self.assertIn(w1.dashboard, models.Dashboard.all(self.u2.org, self.u2.group_ids, None))

    def test_returns_dashboards_from_current_org_only(self):
        w1 = self.factory.create_widget(visualization=None)

        user = self.factory.create_user(org=self.factory.create_org())

        self.assertIn(w1.dashboard, models.Dashboard.all(self.u1.org, self.u1.group_ids, None))
        self.assertNotIn(w1.dashboard, models.Dashboard.all(user.org, user.group_ids, None))

[((22833, 22851), 'redash.models.db.session.flush', 'db.session.flush', ([], {}), '()\n', (22849, 22851), False, 'from redash.models import db, types\n'), ((431, 449), 'redash.models.db.session.flush', 'db.session.flush', ([], {}), '()\n', (447, 449), False, 'from redash.models import db, types\n'), ((558, 576), 'redash.models.db.session.flush', 'db.session.flush', ([], {}), '()\n', (574, 576), False, 'from redash.models import db, types\n'), ((689, 707), 'redash.models.db.session.flush', 'db.session.flush', ([], {}), '()\n', (705, 707), False, 'from redash.models import db, types\n'), ((916, 924), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (922, 924), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((1145, 1153), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (1151, 1153), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((1371, 1379), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (1377, 1379), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((1785, 1815), 'dateutil.parser.parse', 'date_parse', (['"""2015-10-16 20:10"""'], {}), "('2015-10-16 20:10')\n", (1795, 1815), True, 'from dateutil.parser import parse as date_parse\n'), ((1836, 1866), 'dateutil.parser.parse', 'date_parse', (['"""2015-10-15 23:07"""'], {}), "('2015-10-15 23:07')\n", (1846, 1866), True, 'from dateutil.parser import parse as date_parse\n'), ((2440, 2448), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (2446, 2448), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((2924, 2932), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (2930, 2932), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((5909, 5917), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (5915, 5917), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((6328, 6336), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (6334, 6336), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((6905, 6936), 'redash.models.Query.outdated_queries', 'models.Query.outdated_queries', ([], {}), '()\n', (6934, 6936), False, 'from redash import models, redis_connection\n'), ((7455, 7486), 'redash.models.Query.outdated_queries', 'models.Query.outdated_queries', ([], {}), '()\n', (7484, 7486), False, 'from redash import models, redis_connection\n'), ((7931, 7983), 'redash.models.scheduled_queries_executions.update', 'models.scheduled_queries_executions.update', (['query.id'], {}), '(query.id)\n', (7973, 7983), False, 'from redash import models, redis_connection\n'), ((8003, 8034), 'redash.models.Query.outdated_queries', 'models.Query.outdated_queries', ([], {}), '()\n', (8032, 8034), False, 'from redash import models, redis_connection\n'), ((8483, 8514), 'redash.models.Query.outdated_queries', 'models.Query.outdated_queries', ([], {}), '()\n', (8512, 8514), False, 'from redash import models, redis_connection\n'), ((9053, 9084), 'redash.models.Query.outdated_queries', 'models.Query.outdated_queries', ([], {}), '()\n', (9082, 9084), False, 'from redash import models, redis_connection\n'), ((10981, 11012), 'redash.models.Query.outdated_queries', 'models.Query.outdated_queries', ([], {}), '()\n', (11010, 11012), False, 'from redash import models, redis_connection\n'), ((13588, 13619), 'redash.models.Query.outdated_queries', 'models.Query.outdated_queries', ([], {}), '()\n', (13617, 13619), False, 'from redash import models, redis_connection\n'), ((14317, 14348), 'redash.models.Query.outdated_queries', 'models.Query.outdated_queries', ([], {}), '()\n', (14346, 14348), False, 'from redash import models, redis_connection\n'), ((14523, 14541), 'redash.models.db.session.flush', 'db.session.flush', ([], {}), '()\n', (14539, 14541), False, 'from redash.models import db, types\n'), ((14872, 14998), 'redash.models.QueryResult.store_result', 'models.QueryResult.store_result', (['query.org_id', 'query.data_source', 'query.query_hash', 'query.query_text', '"""1"""', '(123)', 'yesterday'], {}), "(query.org_id, query.data_source, query.\n    query_hash, query.query_text, '1', 123, yesterday)\n", (14903, 14998), False, 'from redash import models, redis_connection\n'), ((15306, 15324), 'redash.models.db.session.flush', 'db.session.flush', ([], {}), '()\n', (15322, 15324), False, 'from redash.models import db, types\n'), ((15668, 15687), 'redash.models.db.session.commit', 'db.session.commit', ([], {}), '()\n', (15685, 15687), False, 'from redash.models import db, types\n'), ((15720, 15738), 'redash.models.db.session.flush', 'db.session.flush', ([], {}), '()\n', (15736, 15738), False, 'from redash.models import db, types\n'), ((16184, 16203), 'redash.models.db.session.commit', 'db.session.commit', ([], {}), '()\n', (16201, 16203), False, 'from redash.models import db, types\n'), ((16236, 16254), 'redash.models.db.session.flush', 'db.session.flush', ([], {}), '()\n', (16252, 16254), False, 'from redash.models import db, types\n'), ((16692, 16710), 'redash.models.db.session.flush', 'db.session.flush', ([], {}), '()\n', (16708, 16710), False, 'from redash.models import db, types\n'), ((17134, 17152), 'redash.models.db.session.flush', 'db.session.flush', ([], {}), '()\n', (17150, 17152), False, 'from redash.models import db, types\n'), ((17563, 17631), 'redash.models.Group', 'models.Group', ([], {'name': '"""g1"""', 'org': 'ds1.org', 'permissions': "['create', 'view']"}), "(name='g1', org=ds1.org, permissions=['create', 'view'])\n", (17575, 17631), False, 'from redash import models, redis_connection\n'), ((17649, 17717), 'redash.models.Group', 'models.Group', ([], {'name': '"""g2"""', 'org': 'ds1.org', 'permissions': "['create', 'view']"}), "(name='g2', org=ds1.org, permissions=['create', 'view'])\n", (17661, 17717), False, 'from redash import models, redis_connection\n'), ((18104, 18122), 'redash.models.db.session.flush', 'db.session.flush', ([], {}), '()\n', (18120, 18122), False, 'from redash.models import db, types\n'), ((19052, 19071), 'redash.models.db.session.commit', 'db.session.commit', ([], {}), '()\n', (19069, 19071), False, 'from redash.models import db, types\n'), ((19708, 19749), 'redash.models.Group', 'models.Group', ([], {'id': '(999)', 'name': '"""g1"""', 'org': 'org1'}), "(id=999, name='g1', org=org1)\n", (19720, 19749), False, 'from redash import models, redis_connection\n'), ((19776, 19817), 'redash.models.Group', 'models.Group', ([], {'id': '(888)', 'name': '"""g2"""', 'org': 'org1'}), "(id=888, name='g2', org=org1)\n", (19788, 19817), False, 'from redash import models, redis_connection\n'), ((19847, 19888), 'redash.models.Group', 'models.Group', ([], {'id': '(777)', 'name': '"""g1"""', 'org': 'org2'}), "(id=777, name='g1', org=org2)\n", (19859, 19888), False, 'from redash import models, redis_connection\n'), ((19907, 19952), 'redash.models.Group.find_by_name', 'models.Group.find_by_name', (['org1', "['g1', 'g2']"], {}), "(org1, ['g1', 'g2'])\n", (19932, 19952), False, 'from redash import models, redis_connection\n'), ((20189, 20230), 'redash.models.Group', 'models.Group', ([], {'id': '(999)', 'name': '"""g1"""', 'org': 'org1'}), "(id=999, name='g1', org=org1)\n", (20201, 20230), False, 'from redash import models, redis_connection\n'), ((20548, 20574), 'redash.utils.gen_query_hash', 'gen_query_hash', (['self.query'], {}), '(self.query)\n', (20562, 20574), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((20624, 20632), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (20630, 20632), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((20726, 20871), 'redash.models.QueryResult.store_result', 'models.QueryResult.store_result', (['self.data_source.org_id', 'self.data_source', 'self.query_hash', 'self.query', 'self.data', 'self.runtime', 'self.utcnow'], {}), '(self.data_source.org_id, self.data_source,\n    self.query_hash, self.query, self.data, self.runtime, self.utcnow)\n', (20757, 20871), False, 'from redash import models, redis_connection\n'), ((21422, 21467), 'datetime.datetime.utcfromtimestamp', 'datetime.datetime.utcfromtimestamp', (['timestamp'], {}), '(timestamp)\n', (21456, 21467), False, 'import datetime\n'), ((21476, 21494), 'redash.models.db.session.flush', 'db.session.flush', ([], {}), '()\n', (21492, 21494), False, 'from redash.models import db, types\n'), ((21896, 21926), 'redash.models.Event.record', 'models.Event.record', (['raw_event'], {}), '(raw_event)\n', (21915, 21926), False, 'from redash import models, redis_connection\n'), ((21935, 21953), 'redash.models.db.session.flush', 'db.session.flush', ([], {}), '()\n', (21951, 21953), False, 'from redash.models import db, types\n'), ((22435, 22465), 'redash.models.Event.record', 'models.Event.record', (['raw_event'], {}), '(raw_event)\n', (22454, 22465), False, 'from redash import models, redis_connection\n'), ((25240, 25258), 'redash.models.db.session.flush', 'db.session.flush', ([], {}), '()\n', (25256, 25258), False, 'from redash.models import db, types\n'), ((955, 982), 'datetime.timedelta', 'datetime.timedelta', ([], {'hours': '(2)'}), '(hours=2)\n', (973, 982), False, 'import datetime\n'), ((1007, 1062), 'redash.models.should_schedule_next', 'models.should_schedule_next', (['two_hours_ago', 'now', '"""3600"""'], {}), "(two_hours_ago, now, '3600')\n", (1034, 1062), False, 'from redash import models, redis_connection\n'), ((1187, 1217), 'datetime.timedelta', 'datetime.timedelta', ([], {'minutes': '(30)'}), '(minutes=30)\n', (1205, 1217), False, 'import datetime\n'), ((1243, 1301), 'redash.models.should_schedule_next', 'models.should_schedule_next', (['half_an_hour_ago', 'now', '"""3600"""'], {}), "(half_an_hour_ago, now, '3600')\n", (1270, 1301), False, 'from redash import models, redis_connection\n'), ((1406, 1432), 'datetime.timedelta', 'datetime.timedelta', ([], {'days': '(1)'}), '(days=1)\n', (1424, 1432), False, 'import datetime\n'), ((1468, 1495), 'datetime.timedelta', 'datetime.timedelta', ([], {'hours': '(3)'}), '(hours=3)\n', (1486, 1495), False, 'import datetime\n'), ((1589, 1657), 'redash.models.should_schedule_next', 'models.should_schedule_next', (['yesterday', 'now', '"""86400"""', 'scheduled_time'], {}), "(yesterday, now, '86400', scheduled_time)\n", (1616, 1657), False, 'from redash import models, redis_connection\n'), ((1919, 1981), 'redash.models.should_schedule_next', 'models.should_schedule_next', (['yesterday', 'now', '"""86400"""', 'schedule'], {}), "(yesterday, now, '86400', schedule)\n", (1946, 1981), False, 'from redash import models, redis_connection\n'), ((2296, 2357), 'redash.models.should_schedule_next', 'models.should_schedule_next', (['previous', 'now', '"""86400"""', 'schedule'], {}), "(previous, now, '86400', schedule)\n", (2323, 2357), False, 'from redash import models, redis_connection\n'), ((2479, 2505), 'datetime.timedelta', 'datetime.timedelta', ([], {'days': '(4)'}), '(days=4)\n', (2497, 2505), False, 'import datetime\n'), ((2579, 2606), 'datetime.timedelta', 'datetime.timedelta', ([], {'hours': '(3)'}), '(hours=3)\n', (2597, 2606), False, 'import datetime\n'), ((2700, 2787), 'redash.models.should_schedule_next', 'models.should_schedule_next', (['four_days_ago', 'now', 'three_day_interval', 'scheduled_time'], {}), '(four_days_ago, now, three_day_interval,\n    scheduled_time)\n', (2727, 2787), False, 'from redash import models, redis_connection\n'), ((2963, 2989), 'datetime.timedelta', 'datetime.timedelta', ([], {'days': '(2)'}), '(days=2)\n', (2981, 2989), False, 'import datetime\n'), ((3063, 3090), 'datetime.timedelta', 'datetime.timedelta', ([], {'hours': '(3)'}), '(hours=3)\n', (3081, 3090), False, 'import datetime\n'), ((3185, 3272), 'redash.models.should_schedule_next', 'models.should_schedule_next', (['four_days_ago', 'now', 'three_day_interval', 'scheduled_time'], {}), '(four_days_ago, now, three_day_interval,\n    scheduled_time)\n', (3212, 3272), False, 'from redash import models, redis_connection\n'), ((3603, 3675), 'redash.models.should_schedule_next', 'models.should_schedule_next', (['previous', 'now', 'three_day_interval', 'schedule'], {}), '(previous, now, three_day_interval, schedule)\n', (3630, 3675), False, 'from redash import models, redis_connection\n'), ((4195, 4203), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (4201, 4203), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((4336, 4363), 'datetime.timedelta', 'datetime.timedelta', ([], {'weeks': '(3)'}), '(weeks=3)\n', (4354, 4363), False, 'import datetime\n'), ((4394, 4420), 'datetime.timedelta', 'datetime.timedelta', ([], {'days': '(1)'}), '(days=1)\n', (4412, 4420), False, 'import datetime\n'), ((4496, 4523), 'datetime.timedelta', 'datetime.timedelta', ([], {'hours': '(3)'}), '(hours=3)\n', (4514, 4523), False, 'import datetime\n'), ((4617, 4718), 'redash.models.should_schedule_next', 'models.should_schedule_next', (['three_weeks_ago', 'now', 'three_week_interval', 'scheduled_time', '"""Tuesday"""'], {}), "(three_weeks_ago, now, three_week_interval,\n    scheduled_time, 'Tuesday')\n", (4644, 4718), False, 'from redash import models, redis_connection\n'), ((5294, 5302), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (5300, 5302), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((5433, 5460), 'datetime.timedelta', 'datetime.timedelta', ([], {'weeks': '(3)'}), '(weeks=3)\n', (5451, 5460), False, 'import datetime\n'), ((5490, 5516), 'datetime.timedelta', 'datetime.timedelta', ([], {'days': '(1)'}), '(days=1)\n', (5508, 5516), False, 'import datetime\n'), ((5592, 5619), 'datetime.timedelta', 'datetime.timedelta', ([], {'hours': '(3)'}), '(hours=3)\n', (5610, 5619), False, 'import datetime\n'), ((5714, 5816), 'redash.models.should_schedule_next', 'models.should_schedule_next', (['three_weeks_ago', 'now', 'three_week_interval', 'scheduled_time', '"""Thursday"""'], {}), "(three_weeks_ago, now, three_week_interval,\n    scheduled_time, 'Thursday')\n", (5741, 5816), False, 'from redash import models, redis_connection\n'), ((5948, 5975), 'datetime.timedelta', 'datetime.timedelta', ([], {'hours': '(2)'}), '(hours=2)\n', (5966, 5975), False, 'import datetime\n'), ((6000, 6067), 'redash.models.should_schedule_next', 'models.should_schedule_next', (['two_hours_ago', 'now', '"""3600"""'], {'failures': '(5)'}), "(two_hours_ago, now, '3600', failures=5)\n", (6027, 6067), False, 'from redash import models, redis_connection\n'), ((6146, 6214), 'redash.models.should_schedule_next', 'models.should_schedule_next', (['two_hours_ago', 'now', '"""3600"""'], {'failures': '(10)'}), "(two_hours_ago, now, '3600', failures=10)\n", (6173, 6214), False, 'from redash import models, redis_connection\n'), ((6367, 6394), 'datetime.timedelta', 'datetime.timedelta', ([], {'hours': '(2)'}), '(hours=2)\n', (6385, 6394), False, 'import datetime\n'), ((6420, 6488), 'redash.models.should_schedule_next', 'models.should_schedule_next', (['two_hours_ago', 'now', '"""3600"""'], {'failures': '(32)'}), "(two_hours_ago, now, '3600', failures=32)\n", (6447, 6488), False, 'from redash import models, redis_connection\n'), ((7122, 7130), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (7128, 7130), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((7133, 7160), 'datetime.timedelta', 'datetime.timedelta', ([], {'hours': '(2)'}), '(hours=2)\n', (7151, 7160), False, 'import datetime\n'), ((7619, 7627), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (7625, 7627), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((7630, 7657), 'datetime.timedelta', 'datetime.timedelta', ([], {'hours': '(2)'}), '(hours=2)\n', (7648, 7657), False, 'import datetime\n'), ((8144, 8152), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (8150, 8152), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((8155, 8185), 'datetime.timedelta', 'datetime.timedelta', ([], {'minutes': '(30)'}), '(minutes=30)\n', (8173, 8185), False, 'import datetime\n'), ((8655, 8663), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (8661, 8663), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((8666, 8696), 'datetime.timedelta', 'datetime.timedelta', ([], {'minutes': '(30)'}), '(minutes=30)\n', (8684, 8696), False, 'import datetime\n'), ((9648, 9656), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (9654, 9656), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((9659, 9689), 'datetime.timedelta', 'datetime.timedelta', ([], {'minutes': '(10)'}), '(minutes=10)\n', (9677, 9689), False, 'import datetime\n'), ((10650, 10658), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (10656, 10658), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((10661, 10691), 'datetime.timedelta', 'datetime.timedelta', ([], {'minutes': '(10)'}), '(minutes=10)\n', (10679, 10691), False, 'import datetime\n'), ((11737, 11745), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (11743, 11745), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((11748, 11778), 'datetime.timedelta', 'datetime.timedelta', ([], {'minutes': '(10)'}), '(minutes=10)\n', (11766, 11778), False, 'import datetime\n'), ((12465, 12473), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (12471, 12473), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((12476, 12506), 'datetime.timedelta', 'datetime.timedelta', ([], {'minutes': '(16)'}), '(minutes=16)\n', (12494, 12506), False, 'import datetime\n'), ((12826, 12834), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (12832, 12834), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((12837, 12867), 'datetime.timedelta', 'datetime.timedelta', ([], {'minutes': '(17)'}), '(minutes=17)\n', (12855, 12867), False, 'import datetime\n'), ((13249, 13257), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (13255, 13257), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((13260, 13287), 'datetime.timedelta', 'datetime.timedelta', ([], {'hours': '(2)'}), '(hours=2)\n', (13278, 13287), False, 'import datetime\n'), ((13972, 13980), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (13978, 13980), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((13983, 14010), 'datetime.timedelta', 'datetime.timedelta', ([], {'hours': '(2)'}), '(hours=2)\n', (14001, 14010), False, 'import datetime\n'), ((14811, 14819), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (14817, 14819), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((14822, 14848), 'datetime.timedelta', 'datetime.timedelta', ([], {'days': '(1)'}), '(days=1)\n', (14840, 14848), False, 'import datetime\n'), ((15265, 15296), 'redash.models.Query.outdated_queries', 'models.Query.outdated_queries', ([], {}), '()\n', (15294, 15296), False, 'from redash import models, redis_connection\n'), ((15470, 15501), 'redash.models.Query.outdated_queries', 'models.Query.outdated_queries', ([], {}), '()\n', (15499, 15501), False, 'from redash import models, redis_connection\n'), ((15764, 15798), 'redash.models.Widget.query.get', 'models.Widget.query.get', (['widget.id'], {}), '(widget.id)\n', (15787, 15798), False, 'from redash import models, redis_connection\n'), ((16280, 16325), 'redash.models.Alert.query.get', 'models.Alert.query.get', (['subscription.alert.id'], {}), '(subscription.alert.id)\n', (16302, 16325), False, 'from redash import models, redis_connection\n'), ((16358, 16409), 'redash.models.AlertSubscription.query.get', 'models.AlertSubscription.query.get', (['subscription.id'], {}), '(subscription.id)\n', (16392, 16409), False, 'from redash import models, redis_connection\n'), ((16541, 16549), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (16547, 16549), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((16552, 16579), 'datetime.timedelta', 'datetime.timedelta', ([], {'days': '(14)'}), '(days=14)\n', (16570, 16579), False, 'import datetime\n'), ((17006, 17014), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (17012, 17014), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((17017, 17044), 'datetime.timedelta', 'datetime.timedelta', ([], {'days': '(14)'}), '(days=14)\n', (17035, 17044), False, 'import datetime\n'), ((18547, 18604), 'redash.models.Query.all_queries', 'models.Query.all_queries', (['[self.factory.default_group.id]'], {}), '([self.factory.default_group.id])\n', (18571, 18604), False, 'from redash import models, redis_connection\n'), ((18735, 18811), 'redash.models.Query.all_queries', 'models.Query.all_queries', (['[self.factory.default_group.id]'], {'user_id': 'q.user_id'}), '([self.factory.default_group.id], user_id=q.user_id)\n', (18759, 18811), False, 'from redash import models, redis_connection\n'), ((19414, 19437), 'redash.models.User.name.desc', 'models.User.name.desc', ([], {}), '()\n', (19435, 19437), False, 'from redash import models, redis_connection\n'), ((20260, 20309), 'redash.models.Group.find_by_name', 'models.Group.find_by_name', (['org1', "['non-existing']"], {}), "(org1, ['non-existing'])\n", (20285, 20309), False, 'from redash import models, redis_connection\n'), ((22993, 23046), 'redash.models.DataSourceGroup', 'models.DataSourceGroup', ([], {'group': 'd.g1', 'data_source': 'd.ds1'}), '(group=d.g1, data_source=d.ds1)\n', (23015, 23046), False, 'from redash import models, redis_connection\n'), ((23056, 23109), 'redash.models.DataSourceGroup', 'models.DataSourceGroup', ([], {'group': 'd.g2', 'data_source': 'd.ds2'}), '(group=d.g2, data_source=d.ds2)\n', (23078, 23109), False, 'from redash import models, redis_connection\n'), ((24135, 24185), 'redash.models.Dashboard.all', 'models.Dashboard.all', (['d1.user.org', '[0]', 'd1.user.id'], {}), '(d1.user.org, [0], d1.user.id)\n', (24155, 24185), False, 'from redash import models, redis_connection\n'), ((24847, 24905), 'redash.models.Dashboard.all', 'models.Dashboard.all', (['self.u2.org', 'self.u2.group_ids', 'None'], {}), '(self.u2.org, self.u2.group_ids, None)\n', (24867, 24905), False, 'from redash import models, redis_connection\n'), ((25059, 25117), 'redash.models.Dashboard.all', 'models.Dashboard.all', (['self.u1.org', 'self.u1.group_ids', 'None'], {}), '(self.u1.org, self.u1.group_ids, None)\n', (25079, 25117), False, 'from redash import models, redis_connection\n'), ((25697, 25755), 'redash.models.Dashboard.all', 'models.Dashboard.all', (['self.u1.org', 'self.u1.group_ids', 'None'], {}), '(self.u1.org, self.u1.group_ids, None)\n', (25717, 25755), False, 'from redash import models, redis_connection\n'), ((25793, 25851), 'redash.models.Dashboard.all', 'models.Dashboard.all', (['self.u2.org', 'self.u2.group_ids', 'None'], {}), '(self.u2.org, self.u2.group_ids, None)\n', (25813, 25851), False, 'from redash import models, redis_connection\n'), ((26084, 26142), 'redash.models.Dashboard.all', 'models.Dashboard.all', (['self.u1.org', 'self.u1.group_ids', 'None'], {}), '(self.u1.org, self.u1.group_ids, None)\n', (26104, 26142), False, 'from redash import models, redis_connection\n'), ((26183, 26235), 'redash.models.Dashboard.all', 'models.Dashboard.all', (['user.org', 'user.group_ids', 'None'], {}), '(user.org, user.group_ids, None)\n', (26203, 26235), False, 'from redash import models, redis_connection\n'), ((2045, 2053), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (2051, 2053), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((3397, 3405), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (3403, 3405), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((9982, 10013), 'redash.models.Query.outdated_queries', 'models.Query.outdated_queries', ([], {}), '()\n', (10011, 10013), False, 'from redash import models, redis_connection\n'), ((12071, 12102), 'redash.models.Query.outdated_queries', 'models.Query.outdated_queries', ([], {}), '()\n', (12100, 12102), False, 'from redash import models, redis_connection\n'), ((12751, 12782), 'redash.models.Query.outdated_queries', 'models.Query.outdated_queries', ([], {}), '()\n', (12780, 12782), False, 'from redash import models, redis_connection\n'), ((12898, 12929), 'redash.models.Query.outdated_queries', 'models.Query.outdated_queries', ([], {}), '()\n', (12927, 12929), False, 'from redash import models, redis_connection\n'), ((15115, 15148), 'redash.models.Group.id.in_', 'models.Group.id.in_', (['query.groups'], {}), '(query.groups)\n', (15134, 15148), False, 'from redash import models, redis_connection\n'), ((15185, 15233), 'redash.models.Query.all_queries', 'models.Query.all_queries', (['[g.id for g in groups]'], {}), '([g.id for g in groups])\n', (15209, 15233), False, 'from redash import models, redis_connection\n'), ((15387, 15435), 'redash.models.Query.all_queries', 'models.Query.all_queries', (['[g.id for g in groups]'], {}), '([g.id for g in groups])\n', (15411, 15435), False, 'from redash import models, redis_connection\n'), ((16830, 16857), 'redash.models.QueryResult.unused', 'models.QueryResult.unused', ([], {}), '()\n', (16855, 16857), False, 'from redash import models, redis_connection\n'), ((16894, 16921), 'redash.models.QueryResult.unused', 'models.QueryResult.unused', ([], {}), '()\n', (16919, 16921), False, 'from redash import models, redis_connection\n'), ((17251, 17278), 'redash.models.QueryResult.unused', 'models.QueryResult.unused', ([], {}), '()\n', (17276, 17278), False, 'from redash import models, redis_connection\n'), ((17326, 17353), 'redash.models.QueryResult.unused', 'models.QueryResult.unused', ([], {}), '()\n', (17351, 17353), False, 'from redash import models, redis_connection\n'), ((17943, 17996), 'redash.models.DataSourceGroup', 'models.DataSourceGroup', ([], {'group': 'group1', 'data_source': 'ds1'}), '(group=group1, data_source=ds1)\n', (17965, 17996), False, 'from redash import models, redis_connection\n'), ((18027, 18080), 'redash.models.DataSourceGroup', 'models.DataSourceGroup', ([], {'group': 'group2', 'data_source': 'ds2'}), '(group=group2, data_source=ds2)\n', (18049, 18080), False, 'from redash import models, redis_connection\n'), ((18154, 18191), 'redash.models.Query.all_queries', 'models.Query.all_queries', (['[group1.id]'], {}), '([group1.id])\n', (18178, 18191), False, 'from redash import models, redis_connection\n'), ((18228, 18265), 'redash.models.Query.all_queries', 'models.Query.all_queries', (['[group1.id]'], {}), '([group1.id])\n', (18252, 18265), False, 'from redash import models, redis_connection\n'), ((18299, 18347), 'redash.models.Query.all_queries', 'models.Query.all_queries', (['[group1.id, group2.id]'], {}), '([group1.id, group2.id])\n', (18323, 18347), False, 'from redash import models, redis_connection\n'), ((18381, 18429), 'redash.models.Query.all_queries', 'models.Query.all_queries', (['[group1.id, group2.id]'], {}), '([group1.id, group2.id])\n', (18405, 18429), False, 'from redash import models, redis_connection\n'), ((19196, 19253), 'redash.models.Query.all_queries', 'models.Query.all_queries', (['[self.factory.default_group.id]'], {}), '([self.factory.default_group.id])\n', (19220, 19253), False, 'from redash import models, redis_connection\n'), ((24044, 24102), 'redash.models.Dashboard.all', 'models.Dashboard.all', (['d1.user.org', 'd1.user.group_ids', 'None'], {}), '(d1.user.org, d1.user.group_ids, None)\n', (24064, 24102), False, 'from redash import models, redis_connection\n'), ((24332, 24390), 'redash.models.Dashboard.all', 'models.Dashboard.all', (['self.u1.org', 'self.u1.group_ids', 'None'], {}), '(self.u1.org, self.u1.group_ids, None)\n', (24352, 24390), False, 'from redash import models, redis_connection\n'), ((24452, 24510), 'redash.models.Dashboard.all', 'models.Dashboard.all', (['self.u2.org', 'self.u2.group_ids', 'None'], {}), '(self.u2.org, self.u2.group_ids, None)\n', (24472, 24510), False, 'from redash import models, redis_connection\n'), ((24575, 24633), 'redash.models.Dashboard.all', 'models.Dashboard.all', (['self.u2.org', 'self.u2.group_ids', 'None'], {}), '(self.u2.org, self.u2.group_ids, None)\n', (24595, 24633), False, 'from redash import models, redis_connection\n'), ((24698, 24756), 'redash.models.Dashboard.all', 'models.Dashboard.all', (['self.u1.org', 'self.u1.group_ids', 'None'], {}), '(self.u1.org, self.u1.group_ids, None)\n', (24718, 24756), False, 'from redash import models, redis_connection\n'), ((25290, 25354), 'redash.models.Dashboard.all', 'models.Dashboard.all', (['self.u1.org', 'self.u1.group_ids', 'self.u1.id'], {}), '(self.u1.org, self.u1.group_ids, self.u1.id)\n', (25310, 25354), False, 'from redash import models, redis_connection\n'), ((25388, 25438), 'redash.models.Dashboard.all', 'models.Dashboard.all', (['self.u1.org', '[0]', 'self.u1.id'], {}), '(self.u1.org, [0], self.u1.id)\n', (25408, 25438), False, 'from redash import models, redis_connection\n'), ((25475, 25539), 'redash.models.Dashboard.all', 'models.Dashboard.all', (['self.u2.org', 'self.u2.group_ids', 'self.u2.id'], {}), '(self.u2.org, self.u2.group_ids, self.u2.id)\n', (25495, 25539), False, 'from redash import models, redis_connection\n'), ((2106, 2132), 'datetime.timedelta', 'datetime.timedelta', ([], {'days': '(2)'}), '(days=2)\n', (2124, 2132), False, 'import datetime\n'), ((3460, 3486), 'datetime.timedelta', 'datetime.timedelta', ([], {'days': '(2)'}), '(days=2)\n', (3478, 3486), False, 'import datetime\n'), ((8959, 8985), 'datetime.timedelta', 'datetime.timedelta', ([], {'days': '(1)'}), '(days=1)\n', (8977, 8985), False, 'import datetime\n'), ((13165, 13173), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (13171, 13173), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((13176, 13202), 'datetime.timedelta', 'datetime.timedelta', ([], {'days': '(1)'}), '(days=1)\n', (13194, 13202), False, 'import datetime\n'), ((13888, 13896), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (13894, 13896), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((13899, 13925), 'datetime.timedelta', 'datetime.timedelta', ([], {'days': '(1)'}), '(days=1)\n', (13917, 13925), False, 'import datetime\n'), ((4274, 4282), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (4280, 4282), False, 'from redash.utils import gen_query_hash, utcnow\n'), ((5372, 5380), 'redash.utils.utcnow', 'utcnow', ([], {}), '()\n', (5378, 5380), False, 'from redash.utils import gen_query_hash, utcnow\n')]