C
C#9mo ago
solomoncyj

looking onto how to improve my code

files below
12 Replies
solomoncyj
solomoncyjOP9mo ago
solomoncyj
solomoncyjOP9mo ago
releaseAPI
86368F9396007FD448EFF1463CCDCDAF5DAF55A2 eve-online-1.2.0-full.nupkg 182511818
7C6E11E134902CF393D0E42F84D91C29E4A5ED76 eve-online-1.2.1-delta.nupkg 74605
CC3966CB017A22F9C5C723AC955E4D8E4A03AF0E eve-online-1.2.1-full.nupkg 182511844
E11AFDFCEF670271CD07DC2E15CD9E6B854FE088 eve-online-1.2.2-delta.nupkg 114227
C1F7B61FAE006BE35B07089CF2BD37E1558FA59F eve-online-1.2.2-full.nupkg 182514146
83382B96BD1ED64D381EBF87997B5575DDE45176 eve-online-1.2.3-delta.nupkg 399738
C31685F8EBD7B412AAD1AEBC577B7481B54A1391 eve-online-1.2.3-full.nupkg 182923887
C819327D11D4721ECEC7FD52FDF3758D1394A33C eve-online-1.2.4-delta.nupkg 73349
A8FB55D1789ACAF29B6651B18A77A43AFDA5076F eve-online-1.2.4-full.nupkg 182924806
BECFA6F482062FC4ECB22B2B295BCF65976DC297 eve-online-1.2.5-delta.nupkg 504867
F276D93C71478399932D37CCE73AD375227ACB21 eve-online-1.2.5-full.nupkg 183099140
ADBA8916763836449AE90FDB6E7009EAA11B39AD eve-online-1.2.6-delta.nupkg 72219
D73EAB601E58D92D5596038DEC46347DD62FE9B2 eve-online-1.2.6-full.nupkg 183099740
795D992FBE9B9F7375605E64D8F3A99809BA30C4 eve-online-1.2.7-delta.nupkg 109117
B2F2F02D65D2F5A450D55647451C03C37CE0654C eve-online-1.2.7-full.nupkg 183100576
34DB8AFF22BFDD796DF837B4106351BCCE4E5B28 eve-online-1.2.8-delta.nupkg 94831
DE899461D60634229CDA4CC3EA324F7902F77E69 eve-online-1.2.8-full.nupkg 183102763
7601D389039C84250116D24EBE35B0EC5CFA6A5D eve-online-1.2.9-delta.nupkg 293007
78BEE4C839C3381B80560AD9CAF8CA30442A97B8 eve-online-1.2.9-full.nupkg 183171796
E8D5D7B0D41A64307B6C5DA4E57E51C4A192492A eve-online-1.2.10-delta.nupkg 78076
D9C270B466BC02BF11B1E4BBFF193CDE8CA75A4A eve-online-1.2.10-full.nupkg 183172498
F5707140C03C454AAB9C2EDB230859CFB7E85C3F eve-online-1.2.11-delta.nupkg 128044
33CD4CA29E793663F11008E8331DEEDBBFD17480 eve-online-1.2.11-full.nupkg 183154317
86368F9396007FD448EFF1463CCDCDAF5DAF55A2 eve-online-1.2.0-full.nupkg 182511818
7C6E11E134902CF393D0E42F84D91C29E4A5ED76 eve-online-1.2.1-delta.nupkg 74605
CC3966CB017A22F9C5C723AC955E4D8E4A03AF0E eve-online-1.2.1-full.nupkg 182511844
E11AFDFCEF670271CD07DC2E15CD9E6B854FE088 eve-online-1.2.2-delta.nupkg 114227
C1F7B61FAE006BE35B07089CF2BD37E1558FA59F eve-online-1.2.2-full.nupkg 182514146
83382B96BD1ED64D381EBF87997B5575DDE45176 eve-online-1.2.3-delta.nupkg 399738
C31685F8EBD7B412AAD1AEBC577B7481B54A1391 eve-online-1.2.3-full.nupkg 182923887
C819327D11D4721ECEC7FD52FDF3758D1394A33C eve-online-1.2.4-delta.nupkg 73349
A8FB55D1789ACAF29B6651B18A77A43AFDA5076F eve-online-1.2.4-full.nupkg 182924806
BECFA6F482062FC4ECB22B2B295BCF65976DC297 eve-online-1.2.5-delta.nupkg 504867
F276D93C71478399932D37CCE73AD375227ACB21 eve-online-1.2.5-full.nupkg 183099140
ADBA8916763836449AE90FDB6E7009EAA11B39AD eve-online-1.2.6-delta.nupkg 72219
D73EAB601E58D92D5596038DEC46347DD62FE9B2 eve-online-1.2.6-full.nupkg 183099740
795D992FBE9B9F7375605E64D8F3A99809BA30C4 eve-online-1.2.7-delta.nupkg 109117
B2F2F02D65D2F5A450D55647451C03C37CE0654C eve-online-1.2.7-full.nupkg 183100576
34DB8AFF22BFDD796DF837B4106351BCCE4E5B28 eve-online-1.2.8-delta.nupkg 94831
DE899461D60634229CDA4CC3EA324F7902F77E69 eve-online-1.2.8-full.nupkg 183102763
7601D389039C84250116D24EBE35B0EC5CFA6A5D eve-online-1.2.9-delta.nupkg 293007
78BEE4C839C3381B80560AD9CAF8CA30442A97B8 eve-online-1.2.9-full.nupkg 183171796
E8D5D7B0D41A64307B6C5DA4E57E51C4A192492A eve-online-1.2.10-delta.nupkg 78076
D9C270B466BC02BF11B1E4BBFF193CDE8CA75A4A eve-online-1.2.10-full.nupkg 183172498
F5707140C03C454AAB9C2EDB230859CFB7E85C3F eve-online-1.2.11-delta.nupkg 128044
33CD4CA29E793663F11008E8331DEEDBBFD17480 eve-online-1.2.11-full.nupkg 183154317
VercelApi
{"PackageIdentifier":"CCPGames.EVEOnline","Versions":["1.2.8","1.2.7","1.2.6","1.2.5","1.2.4","1.2.3","1.2.2","1.2.1","1.2.0","1.1.0","1.0.2","1.0.1","1.0.0","0.4.9","0.4.8","0.4.7","0.4.6","0.4.5","0.4.4","0.4.3","0.4.2","0.4.0","0.3.4","0.3.3","0.3.2","0.3.1","0.3.0"]}
{"PackageIdentifier":"CCPGames.EVEOnline","Versions":["1.2.8","1.2.7","1.2.6","1.2.5","1.2.4","1.2.3","1.2.2","1.2.1","1.2.0","1.1.0","1.0.2","1.0.1","1.0.0","0.4.9","0.4.8","0.4.7","0.4.6","0.4.5","0.4.4","0.4.3","0.4.2","0.4.0","0.3.4","0.3.3","0.3.2","0.3.1","0.3.0"]}
maxmahem
maxmahem9mo ago
so... minor low hanging fruit, you can and should reused the HttpClient. you can also just use a statement based using. using HttpClient client = new();
canton7
canton79mo ago
There's no validation that the data you get back is in the correct format. using Newtonsoft.Json;, then you don't need Newtonsoft.Json.JsonConvert.DeserializeObject, just JsonConvert...
maxmahem
maxmahem9mo ago
I'd also use linq instead of your loops, but that's just cause I love LINQ so much.
canton7
canton79mo ago
Put constants like those URLs in static readonly fields, rather than just hard-coding thjem
maxmahem
maxmahem9mo ago
C#
var versions = from line in releasesData.Split('\n')
let data = line.Split(' ')[1]
where !data.Contains("delta")
select data.Split('-')[2];
C#
var versions = from line in releasesData.Split('\n')
let data = line.Split(' ')[1]
where !data.Contains("delta")
select data.Split('-')[2];
Then later:
C#
var diff = versions.Except(current);
C#
var diff = versions.Except(current);
there is no need to ToList all the time. If console formatting is super important to you, check out a library like Spectr or whatever. otherwise, I mean the two biggest no-nos I saw were not reusing the HttpClient and the excess to list.
solomoncyj
solomoncyjOP9mo ago
i know, i am just new to the linq so i am trying to figure out how to linq
maxmahem
maxmahem9mo ago
most of the rest is just outdated syntax and preference. fair enough. Well, there isn't anything especially wrong with your first loop. Some people might prefer that logic. But you don't need to ToList versions later on. You can just save the result of versions.Except and foreach that. or even move it into the foreach call, and save a line. my personal rule of thumb is less, more complex code is generally better than more verbose "simpler" code. Because the fewer llines of code I have the fewer I have to try and keep in memory.
solomoncyj
solomoncyjOP9mo ago
the reson of the !contains("delta") was to remove duplicate data. any faster way?
maxmahem
maxmahem9mo ago
mmm... probably not. Contains should be pretty well optimized. It's going to use vector instructions to examine the string quickly. I suppose since you know that if its present it's going to be at a certain position you could slice the string with Span and search a smaller segment. Though I think that's a questionable improvement. It makes the code less flexible and speed is hardly going to matter here. Honestly, you might consider using regex instead. It will be slower, but a single regex pattern is easier to update and understand than a lot of split and indexed based magic. And more adaptable to changes in format. Don't worry about speed unless it really matters. While string operations and parsing can be slow your bottleneck here is almost certainly going to be the file download anyways. So optimize first for flexibility and readability, rather than performance, I say. actually regex might not even be slower than a lot of splits, come to think of it. You'd have to benchmark to determine I suppose.
Want results from more Discord servers?
Add your server