66using RadarrAPI . Database ;
77using RadarrAPI . Update ;
88using RadarrAPI . Update . Data ;
9+ using StatsdClient ;
910using Branch = RadarrAPI . Update . Branch ;
1011
1112namespace RadarrAPI . Controllers
@@ -24,122 +25,130 @@ public UpdateController(DatabaseContext database)
2425 [ HttpGet ]
2526 public object GetChanges ( [ FromRoute ( Name = "branch" ) ] Branch updateBranch , [ FromQuery ( Name = "version" ) ] string urlVersion , [ FromQuery ( Name = "os" ) ] OperatingSystem operatingSystem )
2627 {
27- var updates = _database . UpdateEntities
28+ using ( DogStatsd . StartTimer ( "controller.update.get_changes.time" ) )
29+ {
30+ DogStatsd . Increment ( "controller.update.get_changes.count" ) ;
31+
32+ var updates = _database . UpdateEntities
2833 . Include ( x => x . UpdateFiles )
2934 . Where ( x => x . Branch == updateBranch && x . UpdateFiles . Any ( u => u . OperatingSystem == operatingSystem ) )
3035 . OrderByDescending ( x => x . ReleaseDate )
3136 . Take ( 5 ) ;
3237
33- var response = new List < UpdatePackage > ( ) ;
38+ var response = new List < UpdatePackage > ( ) ;
3439
35- foreach ( var update in updates )
36- {
37- var updateFile = update . UpdateFiles . FirstOrDefault ( u => u . OperatingSystem == operatingSystem ) ;
38- if ( updateFile == null ) continue ;
40+ foreach ( var update in updates )
41+ {
42+ var updateFile = update . UpdateFiles . FirstOrDefault ( u => u . OperatingSystem == operatingSystem ) ;
43+ if ( updateFile == null ) continue ;
3944
40- UpdateChanges updateChanges = null ;
45+ UpdateChanges updateChanges = null ;
4146
42- if ( update . New . Count != 0 || update . Fixed . Count != 0 )
43- {
44- updateChanges = new UpdateChanges
47+ if ( update . New . Count != 0 || update . Fixed . Count != 0 )
4548 {
46- New = update . New ,
47- Fixed = update . Fixed
48- } ;
49+ updateChanges = new UpdateChanges
50+ {
51+ New = update . New ,
52+ Fixed = update . Fixed
53+ } ;
54+ }
55+
56+ response . Add ( new UpdatePackage
57+ {
58+ Version = update . Version ,
59+ ReleaseDate = update . ReleaseDate ,
60+ Filename = updateFile . Filename ,
61+ Url = updateFile . Url ,
62+ Changes = updateChanges ,
63+ Hash = updateFile . Hash ,
64+ Branch = update . Branch . ToString ( ) . ToLower ( )
65+ } ) ;
4966 }
5067
51- response . Add ( new UpdatePackage
52- {
53- Version = update . Version ,
54- ReleaseDate = update . ReleaseDate ,
55- Filename = updateFile . Filename ,
56- Url = updateFile . Url ,
57- Changes = updateChanges ,
58- Hash = updateFile . Hash ,
59- Branch = update . Branch . ToString ( ) . ToLower ( )
60- } ) ;
68+ return response ;
6169 }
62-
63- return response ;
6470 }
6571
6672 [ Route ( "{branch}" ) ]
6773 [ HttpGet ]
6874 public object GetUpdates ( [ FromRoute ( Name = "branch" ) ] Branch updateBranch , [ FromQuery ( Name = "version" ) ] string urlVersion , [ FromQuery ( Name = "os" ) ] OperatingSystem operatingSystem )
6975 {
70- Version version ;
71-
7276 // Check given version
73- if ( ! Version . TryParse ( urlVersion , out version ) )
77+ if ( ! Version . TryParse ( urlVersion , out Version version ) )
7478 {
7579 return new
7680 {
7781 ErrorMessage = "Invalid version number specified."
7882 } ;
7983 }
8084
81- // Grab latest update based on branch and operatingsystem
82- var update = _database . UpdateEntities
83- . Include ( x => x . UpdateFiles )
84- . Where ( x => x . Branch == updateBranch && x . UpdateFiles . Any ( u => u . OperatingSystem == operatingSystem ) )
85- . OrderByDescending ( x => x . ReleaseDate )
86- . Take ( 1 )
87- . FirstOrDefault ( ) ;
88-
89- if ( update == null )
85+ using ( DogStatsd . StartTimer ( "controller.update.get_updates.time" ) )
9086 {
91- return new
87+ DogStatsd . Increment ( "controller.update.get_updates.count" ) ;
88+
89+ // Grab latest update based on branch and operatingsystem
90+ var update = _database . UpdateEntities
91+ . Include ( x => x . UpdateFiles )
92+ . Where ( x => x . Branch == updateBranch && x . UpdateFiles . Any ( u => u . OperatingSystem == operatingSystem ) )
93+ . OrderByDescending ( x => x . ReleaseDate )
94+ . Take ( 1 )
95+ . FirstOrDefault ( ) ;
96+
97+ if ( update == null )
9298 {
93- ErrorMessage = "Latest update not found."
94- } ;
95- }
99+ return new
100+ {
101+ ErrorMessage = "Latest update not found."
102+ } ;
103+ }
96104
97- // Check if update file is present
98- var updateFile = update . UpdateFiles . FirstOrDefault ( u => u . OperatingSystem == operatingSystem ) ;
99- if ( updateFile == null )
100- {
101- return new
105+ // Check if update file is present
106+ var updateFile = update . UpdateFiles . FirstOrDefault ( u => u . OperatingSystem == operatingSystem ) ;
107+ if ( updateFile == null )
102108 {
103- ErrorMessage = "Latest update file not found."
104- } ;
105- }
109+ return new
110+ {
111+ ErrorMessage = "Latest update file not found."
112+ } ;
113+ }
106114
107- // Compare given version and update version
108- var updateVersion = new Version ( update . Version ) ;
109- if ( updateVersion . CompareTo ( version ) <= 0 )
110- {
111- return new UpdatePackageContainer
115+ // Compare given version and update version
116+ var updateVersion = new Version ( update . Version ) ;
117+ if ( updateVersion . CompareTo ( version ) <= 0 )
112118 {
113- Available = false
114- } ;
115- }
119+ return new UpdatePackageContainer
120+ {
121+ Available = false
122+ } ;
123+ }
116124
117- // Get the update changes
118- UpdateChanges updateChanges = null ;
125+ // Get the update changes
126+ UpdateChanges updateChanges = null ;
119127
120- if ( update . New . Count != 0 || update . Fixed . Count != 0 )
121- {
122- updateChanges = new UpdateChanges
128+ if ( update . New . Count != 0 || update . Fixed . Count != 0 )
129+ {
130+ updateChanges = new UpdateChanges
131+ {
132+ New = update . New ,
133+ Fixed = update . Fixed
134+ } ;
135+ }
136+
137+ return new UpdatePackageContainer
123138 {
124- New = update . New ,
125- Fixed = update . Fixed
139+ Available = true ,
140+ UpdatePackage = new UpdatePackage
141+ {
142+ Version = update . Version ,
143+ ReleaseDate = update . ReleaseDate ,
144+ Filename = updateFile . Filename ,
145+ Url = updateFile . Url ,
146+ Changes = updateChanges ,
147+ Hash = updateFile . Hash ,
148+ Branch = update . Branch . ToString ( ) . ToLower ( )
149+ }
126150 } ;
127151 }
128-
129- return new UpdatePackageContainer
130- {
131- Available = true ,
132- UpdatePackage = new UpdatePackage
133- {
134- Version = update . Version ,
135- ReleaseDate = update . ReleaseDate ,
136- Filename = updateFile . Filename ,
137- Url = updateFile . Url ,
138- Changes = updateChanges ,
139- Hash = updateFile . Hash ,
140- Branch = update . Branch . ToString ( ) . ToLower ( )
141- }
142- } ;
143152 }
144153 }
145154}
0 commit comments