ad_page_contract { Show recent GitHub activities @author Gustaf Neumann @creation-date 2022-11-20 } { {page_size:naturalnum,notnull 200} {q:printable,trim ""} } set base_url [ad_conn url] set offset 0 if {$q ne ""} { # escape % and _ for LIKE set escaped [string map [list "%" "\\%" "_" "\\_"] $q] set pattern "%$escaped%" set search_part {where lower(title) like lower(:pattern) or lower(raw_payload::json->'commit'->>'message') like lower(:pattern)} if {0} { # documentation of index creation, suited to cut&paste create extension if not exists pg_trgm; create index github_activity_msg_trgm_idx on github_activity using gin ((lower(raw_payload::json->'commit'->>'message')) gin_trgm_ops); create index github_activity_title_trgm_idx on github_activity using gin (lower(title) gin_trgm_ops); } set q_url [ns_urlencode $q] } else { set search_part "" set q_url "" } db_multirow -extend {date_str time_str repo_base} activity select_activity [subst { select event_id, repo, branch, sha, author_name, author_login, commit_date, created_at, title, url, files_changed, additions, deletions from github_activity $search_part order by commit_date desc limit :page_size offset :offset }] { set time [clock scan [::xo::db::tcl_date $commit_date tz]] set date_str [clock format $time -format "%Y-%m-%d"] set time_str [clock format $time -format "%H:%M:%S"] set repo_base [lindex [split $repo "/"] end] if {$author_login eq "vguerra"} { set author_login "" } }