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']) {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 + 1sid = 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
- 5db84974Log: Apollo window GO, AP56b started, BS1 copy removedmre
- e84586a7Mission AP56bmre
- 15917f03Record PR workflow rule (gitoria#50)mre
- 942ac995status: paused workers statemre
- 44b934e5log: respawn cleanupmre
- 03a80097Log: Anton GC A/Bmre
- c7cdef62Log: Apollo STOP, workers pausedmre
- d0c083fbLog: usage stopmre
- c6d464e5Log: Apollo GO backlog, AP56 and BS1 startedmre
- 1eb6f1a1Missions AP56, BS1mre
- 4871f8adLog: AP52 live on day52, browser gate greenmre
- d9bf2988Merge ap52: day52, tracker#58 server argument, #51 modal close rule, #56 keyed season rowsmre
- c4a60ef2Log: RT52 retest passed, AP52 startedmre
- 83760a55Browser gate: search results belong to the address form of the typed text (tracker#52 navigate replace)mre
- 6e951d91AP52: show-page rows are keyed records; closing a season is one upsert and removes (tracker#56, hybriel#331)mre
- 3bb4ccddAP52: modal close button refers to its nested rule with Style.buttonModalX (tracker#51, hybriel#333)mre
- ba16933fAP52: login callback and title route are static handlers taking the server as third argument (tracker#58, hybriel#332)mre
- 85153900AP52: re-vendor Hybriel set day52 (source 77cfca31, bin 0a8ed496)mre
- 7c051eddLog: hybriel#338 answermre
- d049b8b8Log: HM50 live, #52 donemre