CategoryStatsUpdate and the category_stats table

This is mostly for my own future reference.

I was looking at /categories.php and didn’t see the new filesystems category.

I also note it does not sort by what it says it will sort.

I eventually found it was loading data from this table:

freshports.dvl=# select * from category_stats;
 category_id | port_count |     last_update     
-------------+------------+---------------------
          85 |         27 | 2017-11-30 15:50:34
          69 |          4 | 2017-08-17 18:06:43
          67 |        253 | 2017-11-30 20:28:15
          89 |        758 | 2017-12-05 19:53:55
          32 |       1451 | 2017-12-05 21:15:30
         113 |         54 | 2017-11-30 06:13:35
         130 |          3 | 2017-09-09 20:24:12
          63 |         87 | 2017-11-30 15:50:34
          98 |        165 | 2017-12-02 11:08:42
          66 |        240 | 2017-12-04 09:00:26
          14 |        142 | 2017-11-30 15:50:34
          88 |          9 | 2017-11-02 21:12:58
          24 |        298 | 2017-12-03 12:23:54
         114 |         62 | 2017-11-30 23:45:49
          62 |        610 | 2017-12-05 21:15:30
          53 |         15 | 2017-11-04 11:43:35
          44 |         33 | 2017-12-05 19:01:54
          37 |         40 | 2017-11-21 08:36:27
          27 |        221 | 2017-11-30 15:50:34
          28 |         55 | 2017-12-03 12:23:54
          16 |       1004 | 2017-12-04 21:00:33
           8 |       1684 | 2017-12-05 19:11:21
          96 |        119 | 2017-12-05 09:00:27
          56 |         71 | 2017-12-05 18:25:59
         115 |        131 | 2017-12-03 20:34:57
          68 |         53 | 2017-11-30 06:13:35
          54 |        185 | 2017-12-05 21:04:59
          29 |         51 | 2017-12-04 16:59:20
          74 |        133 | 2017-11-22 23:35:56
          92 |        454 | 2017-12-04 18:54:39
         102 |         79 | 2017-12-05 20:35:45
          82 |         21 | 2017-11-30 15:50:34
          90 |         38 | 2017-11-30 06:13:35
           9 |        327 | 2017-12-04 20:45:56
          46 |          8 | 2017-11-02 21:12:58
          58 |        533 | 2017-12-02 09:22:02
          83 |         35 | 2017-11-30 06:13:35
         101 |        100 | 2017-12-03 12:23:54
         116 |         79 | 2017-11-30 15:50:34
          30 |         45 | 2017-12-01 07:19:54
         128 |        182 | 2017-12-01 22:12:35
           6 |        149 | 2017-12-03 19:39:23
          21 |        590 | 2017-12-04 20:25:18
          59 |       5524 | 2017-12-04 17:09:40
         119 |         28 | 2017-11-30 15:50:34
          84 |        270 | 2017-12-04 13:56:32
         124 |         38 | 2017-10-28 01:32:24
          13 |        144 | 2017-12-03 20:37:27
          20 |       1494 | 2017-12-05 21:51:11
          25 |       1055 | 2017-12-05 18:25:59
         131 |          8 | 2017-12-01 07:04:07
          26 |        138 | 2017-12-03 20:37:17
          43 |         16 | 2017-11-30 06:13:35
         129 |        143 | 2017-12-01 07:19:54
         100 |          7 | 2017-11-04 22:57:12
          47 |         24 | 2017-12-05 19:01:54
          15 |        468 | 2017-12-05 17:00:49
          19 |        847 | 2017-12-04 23:55:05
          35 |        129 | 2017-12-03 19:20:35
          52 |        619 | 2017-12-05 18:53:42
          49 |         11 | 2017-11-02 21:12:58
          64 |         25 | 2017-11-30 06:13:35
          42 |         93 | 2017-12-02 11:04:07
           2 |       2895 | 2017-12-05 21:44:13
          11 |         17 | 2017-11-08 06:04:45
          31 |         43 | 2017-12-05 19:01:54
          38 |        196 | 2017-11-30 15:50:34
          40 |         16 | 2017-10-06 11:18:36
          34 |        141 | 2017-12-02 13:48:41
          55 |        662 | 2017-12-01 22:12:35
          77 |        556 | 2017-11-30 06:13:35
          23 |        317 | 2017-12-05 15:56:04
           5 |       1486 | 2017-12-05 23:31:08
          41 |        237 | 2017-12-05 09:00:27
          97 |       1544 | 2017-12-05 16:44:09
          48 |        255 | 2017-12-05 19:15:49
           4 |       1394 | 2017-12-05 20:52:58
          51 |         10 | 2017-11-02 21:12:58
          91 |        181 | 2017-11-25 20:34:37
           7 |        591 | 2017-12-04 09:00:25
          57 |       2846 | 2017-12-05 22:00:55
          12 |        319 | 2017-12-05 19:01:54
          10 |       6680 | 2017-12-05 20:27:27
          18 |       1996 | 2017-12-05 22:00:55
          81 |         78 | 2017-11-30 20:36:35
           1 |        295 | 2017-12-02 23:10:48
         117 |         82 | 2017-11-16 20:30:44
          33 |        311 | 2017-12-05 13:51:27
         118 |         63 | 2017-10-31 14:57:54
           3 |       1362 | 2017-12-05 19:56:37
          22 |        260 | 2017-12-05 21:00:21
          36 |        132 | 2017-12-05 03:03:38
          39 |        124 | 2017-12-05 19:01:54
          17 |         78 | 2017-12-03 12:23:54
          95 |        228 | 2017-12-03 08:25:32
(95 rows)

That’s all from 2017… 7 years ago.

Grepping for the table name, I found:

CREATE OR REPLACE FUNCTION CategoryStatsUpdate() returns int as $$
BEGIN
 DELETE FROM category_stats;
 INSERT INTO category_stats (
  SELECT categories.id               AS category_id,
         count(ports_active.id)      AS count,
         max(commit_log.commit_date) AS updated
         
    FROM categories, ports_active left outer join commit_log on ( ports_active.last_commit_id = commit_log.id )
   WHERE categories.id   = ports_active.category_id
     AND categories.is_primary
GROUP BY categories.id, categories.name, categories.description, is_primary, categories.element_id
UNION
  SELECT categories.id               AS category_id,
         count(ports_active.id)      AS count,
         max(commit_log.commit_date) AS updated
    FROM ports_categories, categories, ports_active left outer join commit_log on ( ports_active.last_commit_id = commit_log.id )
   WHERE ports_active.id = ports_categories.port_id
     AND categories.id   = ports_categories.category_id
     AND NOT categories.is_primary
GROUP BY categories.id, categories.name, categories.description, is_primary, categories.element_id);

        return 1;
END;
$$ LANGUAGE plpgsql;

I ran it and found three new categories:

freshports.dvl=# select * from CategoryStatsUpdate();
 categorystatsupdate 
---------------------
                   1
(1 row)

freshports.dvl=# select * from category_stats;
 category_id | port_count |     last_update     
-------------+------------+---------------------
         118 |         23 | 2024-10-13 10:08:34
          56 |         61 | 2024-10-17 22:04:57
          23 |        294 | 2024-11-06 15:17:35
          21 |        682 | 2024-11-04 16:50:19
          10 |       8328 | 2024-11-06 15:17:35
          20 |       1610 | 2024-11-06 15:17:35
          92 |        431 | 2024-11-06 15:17:35
          37 |         50 | 2024-10-29 02:08:50
           3 |       1178 | 2024-11-05 18:19:12
          67 |         11 | 2024-08-07 07:46:45
          85 |         33 | 2024-11-02 00:28:32
          55 |        602 | 2024-11-06 15:17:35
         135 |         68 | 2024-10-30 08:40:48
          74 |         91 | 2024-11-06 15:17:35
          59 |       5849 | 2024-11-06 15:17:35
         116 |         70 | 2024-11-04 17:15:06
          66 |        276 | 2024-11-06 15:17:35
          98 |        104 | 2024-11-04 17:00:00
          58 |        345 | 2024-11-06 15:17:35
         119 |         16 | 2024-09-14 18:22:18
          19 |        757 | 2024-11-05 20:24:07
         124 |         39 | 2024-10-23 07:11:50
          77 |         62 | 2024-11-05 01:26:41
          41 |        228 | 2024-11-04 02:39:20
          14 |        131 | 2024-11-04 07:36:54
          17 |         65 | 2024-10-25 12:19:51
          52 |        413 | 2024-11-05 20:20:39
           7 |        684 | 2024-11-06 15:17:35
          88 |          9 | 2024-10-03 14:27:55
          24 |        271 | 2024-11-06 15:17:35
          97 |       3064 | 2024-11-06 15:17:35
          83 |         28 | 2024-10-15 06:19:13
          32 |       1119 | 2024-11-06 15:17:35
         101 |         91 | 2024-10-01 18:56:20
           9 |        265 | 2024-11-05 10:13:27
         130 |        168 | 2024-11-05 06:31:43
           2 |       2567 | 2024-11-06 15:17:35
          34 |        107 | 2024-11-01 17:50:12
          27 |        184 | 2024-11-04 19:16:34
          26 |        144 | 2024-11-03 13:22:25
           6 |         95 | 2024-11-02 13:47:23
          28 |         46 | 2024-10-13 10:13:54
          51 |          7 | 2024-10-03 14:27:55
          63 |         98 | 2024-11-05 16:07:05
          96 |        111 | 2024-11-04 02:39:20
          89 |        447 | 2024-11-06 15:17:35
         102 |         82 | 2024-11-01 20:20:20
         113 |         25 | 2024-08-07 02:23:40
          16 |       1280 | 2024-11-06 15:17:35
          64 |         21 | 2024-10-08 21:36:45
          12 |        306 | 2024-11-03 13:23:40
          91 |        176 | 2024-11-01 16:01:37
          54 |        153 | 2024-11-04 03:07:56
          48 |        521 | 2024-11-06 15:17:35
          81 |         70 | 2024-10-24 05:43:50
         134 |         36 | 2024-10-21 09:36:02
          31 |         32 | 2024-10-09 05:58:59
          68 |         34 | 2024-10-30 09:00:36
         114 |         84 | 2024-11-06 15:17:35
          30 |         32 | 2024-11-06 15:17:35
          29 |         75 | 2024-11-04 10:39:44
          42 |        118 | 2024-10-30 09:00:37
          13 |         99 | 2024-10-31 07:54:16
          95 |        180 | 2024-11-05 18:06:12
         137 |         10 | 2024-10-23 07:11:50
          82 |         11 | 2024-11-03 13:23:27
          36 |        256 | 2024-11-05 07:25:49
         117 |         60 | 2024-10-23 06:30:36
          49 |          9 | 2024-10-03 14:27:55
          90 |         39 | 2024-10-31 07:47:02
          11 |         16 | 2024-10-03 14:27:55
          33 |        318 | 2024-11-06 15:17:35
          18 |       2207 | 2024-11-06 15:17:35
         138 |        140 | 2024-11-06 15:17:35
           8 |       1693 | 2024-11-06 15:17:35
         100 |          5 | 2023-11-06 10:03:47
          35 |        160 | 2024-11-03 19:46:36
           4 |       1271 | 2024-11-06 15:17:35
         131 |        233 | 2024-11-06 15:17:35
          69 |          3 | 2024-09-09 19:11:12
          38 |        350 | 2024-11-06 15:17:35
         133 |         94 | 2024-11-01 16:01:37
          57 |       4575 | 2024-11-06 15:17:35
          39 |        134 | 2024-10-30 16:53:05
          84 |        240 | 2024-11-03 13:22:16
         129 |        148 | 2024-10-23 07:11:50
           5 |       1419 | 2024-11-06 15:17:35
          47 |         13 | 2024-11-03 11:48:23
          25 |        895 | 2024-11-05 18:06:13
         115 |        118 | 2024-10-29 14:38:30
         136 |          7 | 2024-11-04 16:50:19
          53 |          9 | 2024-10-03 14:27:55
          43 |          6 | 2024-09-03 13:51:02
          44 |         20 | 2024-11-03 13:23:26
           1 |        296 | 2024-11-04 19:40:10
          46 |          7 | 2024-10-03 14:27:55
          22 |        189 | 2024-11-06 15:17:35
          15 |        397 | 2024-11-05 16:07:35
(98 rows)

freshports.dvl=# 
Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive

Leave a Comment

Scroll to Top