tracker
All repositories: gitoria
2.8 KB
// tools/count-short-ids.hl — mission 060 (tracker.worldapi.org#27): the short ids in a storage, counted. ONLY on a COPY or with// the app stopped (opening a table rewrites its files, hybriel#21):// TRACKER_STORAGE=$PWD/.scratch/realdata/storage/mpackdb TRACKER_OLD_SHORT_IDS=$PWD/data/old-short-ids.json ./bin/hybriel tools/count-short-ids.hl// → per kind: rows, with a short id, without, malformed; across both: duplicates; the old ids: kept (the show with that oldId// has it), not yet (it has none), lost (it has another one), held by another record; new ids that are old ones.import { MPackDB } from 'hl:mpackdb'import { env } from 'hl:proc'import { readFile } from 'hl:fs'dir = env('TRACKER_STORAGE')oldFile = env('TRACKER_OLD_SHORT_IDS')if (dir == null || !dir.startsWith('/') || oldFile == null || !oldFile.startsWith('/')) { hlError('set TRACKER_STORAGE and TRACKER_OLD_SHORT_IDS, both ABSOLUTE') }chars = 'abcdefghijklmnopqrstuvwxyz0123456789'isShortId = (&s) => {if (s == null || hlTypeName(s) != 'String' || s.length != 5) { return false }let i = 0while (i < 5) {if (!chars.includes(s[i])) { return false }i = i + 1}return true}old = JSON.parse(readFile(oldFile))oldSet = {}oldCount = 0for (k of old.keys()) { oldSet[old[k]] = k oldCount = oldCount + 1 }seen = {}dups = 0oldKept = 0oldLost = 0oldPending = 0oldHeldByOther = 0showsWithOldIdRow = 0for (kind of ['show', 'person']) {let db = new MPackDB(file = dir + '/' + (kind == 'show' ? 'shows' : 'persons') + '.db', primaryKey = '@id', indexes = ['!oldId'])let rows = 0let have = 0let none = 0let bad = 0let sample = ''for (r of db.find(null, null)) {rows = rows + 1let sid = r.shortIdif (sid == null) { none = none + 1 } else if (!isShortId(&sid)) { bad = bad + 1 } else {have = have + 1if (seen[sid] != null) { dups = dups + 1 print('DUPLICATE ' + sid + ': ' + seen[sid] + ' and ' + kind + ' ' + r.id) } else { seen[sid] = kind + ' ' + r.id }if (sample == '' && (kind == 'person' || old[r.oldId] == null)) { sample = sid + ' → ' + r.urlSegment }}if (kind == 'show' && r.oldId != null && old[r.oldId] != null) {showsWithOldIdRow = showsWithOldIdRow + 1if (sid == old[r.oldId]) { oldKept = oldKept + 1 } else if (sid == null) { oldPending = oldPending + 1 } else { oldLost = oldLost + 1 print('OLD LOST ' + r.oldId + ': wants ' + old[r.oldId] + ', has ' + sid) }} else if (sid != null && oldSet[sid] != null) { oldHeldByOther = oldHeldByOther + 1 print('OLD ID ON ANOTHER RECORD ' + sid + ': ' + kind + ' ' + r.id) }}print(kind + 's rows=' + rows + ' withShortId=' + have + ' without=' + none + ' malformed=' + bad + ' sample ' + sample)}print('old ids in the file=' + oldCount + ' shows with such an oldId=' + showsWithOldIdRow + ' kept=' + oldKept + ' notYet=' + oldPending + ' lost=' + oldLost + ' oldIdOnAnotherRecord=' + oldHeldByOther)print('duplicates across shows+persons=' + dups)
Branches
Latest commits
- ae905f15Merge t36a: tracker#36 apply rechecks, reportmre
- 796bfaceT36A: report validated fixes, failed live SSH check and verified rollbackmre
- 55257852log: #53 live, #56 mergedmre
- 78b39f1bMerge hm56-rows: tracker#56 list builders insert oncemre
- 7aea52batmdb fix: protect owners without slugs and record passing gatesmre
- 9b3c2559tmdb fix: revalidate planned identities and reserve target idsmre
- 6da612fclog: T36A tool defectmre
- d56ee0daT36A: report unsafe TMDB apply revalidation and stop before livemre
- 08e55255log: HM56 done, T36A startedmre
- 91bcdf0eAvoid per-row list copies and reproduce keyed-row blockersmre
- 5fd2ac75status: #36 GOmre
- 0d253b45mission: T36Amre
- 2aa22d23log: #36 GOmre
- 833aee2flog: #50 closed, HM56 startedmre
- ac58c1e5mission: HM56mre
- 58979c0clog: HM54 held for decision, DP65 startedmre
- bb2ebc67log: #64 live, #53 mergedmre
- 27cde42fMerge hm53-dom: tracker#53 inputs bound to membersmre
- 2156cc7flog: HM54 reviewmre
- 9fb82efclog: HM54 gap, fill continuesmre