@@ -637,6 +637,28 @@ defmodule Algora.Workspace do
637
637
Repo . all ( query )
638
638
end
639
639
640
+ @ spec count_user_contributions ( list ( String . t ( ) ) , Keyword . t ( ) ) :: { :ok , list ( map ( ) ) } | { :error , term ( ) }
641
+ def count_user_contributions ( ids , opts \\ [ ] ) do
642
+ query =
643
+ from uc in UserContribution ,
644
+ join: u in assoc ( uc , :user ) ,
645
+ join: r in assoc ( uc , :repository ) ,
646
+ join: repo_owner in assoc ( r , :user ) ,
647
+ where: u . id in ^ ids ,
648
+ where: not ilike ( r . name , "%awesome%" ) ,
649
+ where: not ilike ( r . name , "%algorithms%" ) ,
650
+ where: not ilike ( repo_owner . provider_login , "%algorithms%" ) ,
651
+ where: repo_owner . type == :organization or r . stargazers_count > 200 ,
652
+ # where: fragment("? && ?::citext[]", r.tech_stack, ^(opts[:tech_stack] || [])),
653
+ order_by: [
654
+ desc: fragment ( "CASE WHEN ? && ?::citext[] THEN 1 ELSE 0 END" , r . tech_stack , ^ ( opts [ :tech_stack ] || [ ] ) ) ,
655
+ desc: r . stargazers_count
656
+ ] ,
657
+ select_merge: % { user: u , repository: % { r | user: repo_owner } }
658
+
659
+ Repo . aggregate ( query , :sum , :contribution_count ) || 0
660
+ end
661
+
640
662
@ spec upsert_user_contribution ( String . t ( ) , String . t ( ) , integer ( ) ) ::
641
663
{ :ok , UserContribution . t ( ) } | { :error , Ecto.Changeset . t ( ) }
642
664
def upsert_user_contribution ( user_id , repository_id , contribution_count ) do
0 commit comments