Commit Graph

27 Commits

Author SHA1 Message Date
Yorick Peterse 01620dd7e7 Added Event.limit_recent
This will be used to move some querying logic from the users controller
to the Event model (where it belongs).
2015-11-18 13:05:45 +01:00
Yorick Peterse 054f2f98ed Faster way of obtaining latest event update time
Instead of using MAX(events.updated_at) we can simply sort the events in
descending order by the "id" column and grab the first row. In other
words, instead of this:

    SELECT max(events.updated_at) AS max_id
    FROM events
    LEFT OUTER JOIN projects   ON projects.id   = events.project_id
    LEFT OUTER JOIN namespaces ON namespaces.id = projects.namespace_id
    WHERE events.author_id IS NOT NULL
    AND events.project_id IN (13083);

we can use this:

    SELECT events.updated_at AS max_id
    FROM events
    LEFT OUTER JOIN projects   ON projects.id   = events.project_id
    LEFT OUTER JOIN namespaces ON namespaces.id = projects.namespace_id
    WHERE events.author_id IS NOT NULL
    AND events.project_id IN (13083)
    ORDER BY events.id DESC
    LIMIT 1;

This has the benefit that on PostgreSQL a backwards index scan can be
used, which due to the "LIMIT 1" will at most process only a single row.
This in turn greatly speeds up the process of grabbing the latest update
time. This can be confirmed by looking at the query plans. The first
query produces the following plan:

    Aggregate  (cost=43779.84..43779.85 rows=1 width=12) (actual time=2142.462..2142.462 rows=1 loops=1)
      ->  Index Scan using index_events_on_project_id on events  (cost=0.43..43704.69 rows=30060 width=12) (actual time=0.033..2138.086 rows=32769 loops=1)
            Index Cond: (project_id = 13083)
            Filter: (author_id IS NOT NULL)
    Planning time: 1.248 ms
    Execution time: 2142.548 ms

The second query in turn produces the following plan:

    Limit  (cost=0.43..41.65 rows=1 width=16) (actual time=1.394..1.394 rows=1 loops=1)
      ->  Index Scan Backward using events_pkey on events  (cost=0.43..1238907.96 rows=30060 width=16) (actual time=1.394..1.394 rows=1 loops=1)
            Filter: ((author_id IS NOT NULL) AND (project_id = 13083))
            Rows Removed by Filter: 2104
    Planning time: 0.166 ms
    Execution time: 1.408 ms

According to the above plans the 2nd query is around 1500 times faster.
However, re-running the first query produces timings of around 80 ms,
making the 2nd query "only" around 55 times faster.
2015-11-18 13:02:43 +01:00
Jeroen van Baarsen 0c4a70a306 Updated rspec to rspec 3.x syntax
Signed-off-by: Jeroen van Baarsen <jeroenvanbaarsen@gmail.com>
2015-02-12 19:17:35 +01:00
Valeriy Sizov 5715df2067 Merge pull request #8233 from cirosantilli/rm-new-branch-dead
Remove dead Event#new_branch? method
2014-11-05 16:25:35 +02:00
Ciro Santilli c3be1517ae Factor '0' * 40 blank ref constants 2014-11-03 20:37:08 +01:00
Ciro Santilli c49cb40f65 Remove dead Event#new_branch? method 2014-11-03 20:17:02 +01:00
Dmitriy Zaporozhets 73f91da8b1 Fix project deletion and tests 2014-06-17 23:49:17 +03:00
Dmitriy Zaporozhets 36f861f1b1
Re-annotate models
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2014-04-09 15:05:03 +03:00
skv d89527839e fix most of warnings 2013-12-15 00:05:10 +04:00
Dmitriy Zaporozhets e3f1164248 stub notification in event model 2013-03-26 19:27:39 +02:00
Andrew8xx8 839957cf56 Constants in Events looks good now 2013-02-13 15:48:16 +04:00
Dmitriy Zaporozhets 0ff468160e Fixed event.allowed? with event.proper? 2012-12-14 21:54:49 +02:00
Dmitriy Zaporozhets 95c23b2f97 Annotated. schema updated 2012-11-19 21:24:05 +03:00
Vincent Bonmalais 80fb38de7a Remove backward compatibility of factories. 2012-11-13 22:27:45 +11:00
Dmitriy Zaporozhets 41e53eb980 Annotated 2012-10-09 11:14:17 +03:00
randx a82977c648 A bit of test refactoring 2012-09-15 01:00:59 +03:00
Alex Denisov 1f240b09ed User left project event added 2012-09-10 00:27:47 +03:00
Alex Denisov a86bd87afc User joined project event added 2012-09-09 23:18:28 +03:00
Robert Speicher 97423a0bed Add more coverage for model validations and associations 2012-08-29 11:36:02 -04:00
Robert Speicher 9e7d77cece Remove annotations from specs 2012-08-29 10:44:34 -04:00
Robert Speicher 2c95074a5f Remove model specs that are covered by factories_spec 2012-08-29 10:44:34 -04:00
Robert Speicher 7754189187 Fully embrace Ruby 1.9 hash syntax
Didn't bother with files in db/, config/, or features/
2012-08-10 18:25:15 -04:00
randx 6abc649590 Reannotated 2012-06-26 21:23:09 +03:00
Dmitriy Zaporozhets f1799a239f fixed project spec 2012-04-02 08:50:37 +03:00
Dmitriy Zaporozhets 8ee0993fdf Event & Wiki models specs 2012-03-28 22:53:45 +03:00
Dmitriy Zaporozhets dcdb2fdfdb Observe issue, merge request, note creation - create event 2012-02-28 16:01:14 +02:00
Dmitriy Zaporozhets a847501fd2 Event entity created 2012-02-28 15:09:23 +02:00