-
Notifications
You must be signed in to change notification settings - Fork 60
fix: resolve 3 bugs #313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: resolve 3 bugs #313
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,7 +69,7 @@ class CodeforcesController { | |
| */ | ||
| static async getRecentSubmissions(req, res, next) { | ||
| try { | ||
| const count = Math.min(parseInt(req.query.count) || 20, 100); | ||
| const count = Math.min(parseInt(req.query.count, 10) || 20, 100); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
node <<'NODE'
for (const raw of ["-1000000", "10abc", "0", "20"]) {
const count = Math.min(parseInt(raw, 10) || 20, 100);
console.log(`${raw} -> ${count}`);
}
NODE
rg -n -C 4 'getRecentSubmissions|\.limit\(count\)' server/modules/codeforcesRepository: kunalverma2512/CodeLens Length of output: 3675 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
printf 'Package manifests:\n'
fd -a 'package\.json$|package-lock\.json$|pnpm-lock\.yaml$|yarn\.lock$' . | sed 's#^\./##'
printf '\nMongoose versions in manifests/locks:\n'
python3 - <<'PY'
import json, re, pathlib
for p in pathlib.Path('.').rglob('*package-lock.json'):
try:
data=json.loads(p.read_text())
except Exception:
continue
for k,v in data.get('packages',{}).items():
if k.endswith('node_modules/mongoose') or k=='node_modules/mongoose':
print(p, k, v.get('version'))
for p in pathlib.Path('.').rglob('package.json'):
try:
data=json.loads(p.read_text())
except Exception:
continue
deps={}
for sec in ('dependencies','devDependencies'):
deps.update(data.get(sec,{}) or {})
for name,ver in deps.items():
if name=='mongoose':
print(p,'mongoose',ver)
PY
printf '\nMongoose package files in repository:\n'
git ls-files | rg 'node_modules/mongoose/(lib/query|query)\.js$|node_modules/mongoose/package\.json$' | sed -n '1,20p' || true
printf '\nGit diff stat:\n'
git diff --stat -- server/modules/codeforces/controller.js server/modules/codeforces/repository.js server/modules/codeforces/service.jsRepository: kunalverma2512/CodeLens Length of output: 602 🌐 Web query:
💡 Result: In Mongoose, the behavior of the.limit method when passed a negative value is determined by the underlying MongoDB server implementation [1]. A negative limit is treated as a request for a positive number of documents—equal to the absolute value of the negative number provided—with the additional instruction that the cursor should be closed immediately after returning a single batch of results [2][3]. Key aspects of this behavior include: - Cursor Closing: By passing a negative limit, the client tells the server it will not request subsequent batches (i.e., it will not use getMore) [2][3]. - Batch Limitations: Because the cursor closes after one batch, if the result set is large enough that it does not fit into a single batch, the query will return fewer documents than the absolute value of the negative limit specified [2][3][4]. - Undefined Range: The behavior is generally considered undefined for values less than -2^31 and greater than 2^31 [2][3]. Users should generally avoid passing negative values to.limit unless this specific "close-after-batch" behavior is intentionally required, as it can lead to inconsistent result set sizes depending on how data is batched by the MongoDB server [5]. Furthermore, providing extremely large negative numbers may result in a server error indicating that the limit must be non-negative, depending on the specific Mongoose/MongoDB driver version [6]. Citations:
🌐 Web query:
💡 Result: Mongoose's Citations:
Reject invalid
🤖 Prompt for AI Agents |
||
| const submissions = await CodeforcesService.getRecentSubmissions( | ||
| req.user._id, | ||
| count | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -30,12 +30,12 @@ | |||||
| } | ||||||
|
|
||||||
| // Compute streak | ||||||
| const dates = Object.keys(dailyActivity).sort(); | ||||||
| const dates = Object.keys(dailyActivity).sort((a, b) => a - b); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
node <<'NODE'
const dates = ["2026-08-02", "2026-08-01"];
console.log("numeric:", [...dates].sort((a, b) => a - b));
console.log("lexical:", [...dates].sort());
console.log("subtraction:", dates[0] - dates[1]);
NODERepository: kunalverma2512/CodeLens Length of output: 258 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
printf '--- file context ---\n'
sed -n '1,90p' server/modules/codeforces/service.js
printf '\n--- tests/usages for dailyActivity/longestStreak ---\n'
rg -n "dailyActivity|longestStreak|Object\\.keys\\(dailyActivity\\)" .Repository: kunalverma2512/CodeLens Length of output: 252 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
printf '%s\n' '--- file context ---'
sed -n '1,120p' server/modules/codeforces/service.js
printf '%s\n' ''
printf '%s\n' '--- tests/usages for dailyActivity/longestStreak ---'
rg -n "dailyActivity|longestStreak|Object\.keys\(dailyActivity\)" .Repository: kunalverma2512/CodeLens Length of output: 7968 Sort ISO date keys lexicographically.
Use the default lexicographic sort; ISO dates sort chronologically this way. Proposed fix- const dates = Object.keys(dailyActivity).sort((a, b) => a - b);
+ const dates = Object.keys(dailyActivity).sort();📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| let currentStreak = 0; | ||||||
| let longestStreak = 0; | ||||||
| let tempStreak = 0; | ||||||
|
|
||||||
| const today = new Date().toISOString().slice(0, 10); | ||||||
| const sortedDesc = [...dates].reverse(); | ||||||
|
|
||||||
| for (let i = 0; i < sortedDesc.length; i++) { | ||||||
|
|
@@ -147,7 +147,7 @@ | |||||
| let cfUsers; | ||||||
| try { | ||||||
| cfUsers = await cfGetUserInfo(handle); | ||||||
| } catch (err) { | ||||||
| throw new ApiError(404, `Codeforces handle "${handle}" not found.`); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -274,13 +274,13 @@ | |||||
| // 3. Compute contest participation count from rating history | ||||||
| stats.contestsParticipated = ratingHistory.length; | ||||||
| if (ratingHistory.length > 0) { | ||||||
| const ranks = ratingHistory.map((r) => r.rank).filter(Boolean); | ||||||
| const ranks = (ratingHistory ?? []).map((r) => r.rank).filter(Boolean); | ||||||
| stats.bestRank = ranks.length ? Math.min(...ranks) : null; | ||||||
| stats.worstRank = ranks.length ? Math.max(...ranks) : null; | ||||||
| } | ||||||
|
|
||||||
| // 4. Persist grouped submission documents | ||||||
| const submissionDocs = submissions.map((sub) => ({ | ||||||
| const submissionDocs = (submissions ?? []).map((sub) => ({ | ||||||
| user: userId, | ||||||
| submissionId: sub.id, | ||||||
| contestId: sub.contestId, | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: kunalverma2512/CodeLens
Length of output: 202
🏁 Script executed:
Repository: kunalverma2512/CodeLens
Length of output: 322
🏁 Script executed:
Repository: kunalverma2512/CodeLens
Length of output: 5055
Handle numeric bucket keys before sorting
byRating.byRatingcontains non-numeric keys such as"2500plus"and"unrated".parseInt()converts these toNaN, which makes the numeric comparator unreliable for difficulty ordering. Split the mapping/sort/comparison so numeric buckets sort numerically while buckets like"2500plus"and"unrated"are handled consistently.🤖 Prompt for AI Agents