refactor(sort): introduce build_tmp_sort utility; apply to event_presentation and journals
Creates src/lib/ae_core/core__idb_sort.ts with build_tmp_sort() — a shared
helper for computing tmp_sort_1/2/3 fields stored in Dexie. Fixes two bugs
present in all generic _process_generic_props implementations:
- priority encoded as 0/1 ASC (true sorted last); now inverted: true→'0'
- sort stored as unpadded string ("10" < "2"); now 8-char zero-padded
Applied to:
- ae_events__event_presentation: replaces inline specific_processor code
- ae_journals__journal + ae_journals__journal_entry: replaces manual formulas;
journal liveQueries (.reverse().sortBy()) updated to plain .sortBy() since
the inverted encoding handles direction without needing Dexie's .reverse()
Other modules (sessions, presenters, locations, posts, core) left unchanged
until their sort behavior is reviewed separately.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import type { key_val } from '$lib/stores/ae_stores';
|
||||
import { api } from '$lib/api/api';
|
||||
|
||||
import { db_save_ae_obj_li__ae_obj } from '$lib/ae_core/core__idb_dexie';
|
||||
import { build_tmp_sort } from '$lib/ae_core/core__idb_sort';
|
||||
import { db_events } from '$lib/ae_events/db_events';
|
||||
import type { ae_EventPresentation } from '$lib/types/ae_types';
|
||||
|
||||
@@ -681,19 +682,16 @@ export async function process_ae_obj__event_presentation_props({
|
||||
obj.event_session_id = obj.event_session_id_random;
|
||||
if (obj.event_id_random) obj.event_id = obj.event_id_random;
|
||||
|
||||
// Override generic tmp_sort_* with presentation-specific encoding.
|
||||
// WHY: Generic _process_generic_props encodes priority as 0/1 ASC (backwards)
|
||||
// and sort as an unpadded string ("10" < "2"). Presentations also need
|
||||
// start_datetime and code in the sort chain, which are not generic fields.
|
||||
// Desired order: priority DESC → sort ASC → start_datetime ASC → code ASC → name ASC
|
||||
// Encoding trick: invert priority so true→'0' sorts before false→'1' ascending.
|
||||
const p = obj.priority ? '0' : '1';
|
||||
const s = String(Number(obj.sort ?? 0)).padStart(8, '0');
|
||||
const dt = obj.start_datetime ?? '';
|
||||
const code = obj.code ?? '';
|
||||
const name = obj.name ?? '';
|
||||
obj.tmp_sort_1 = `${p}_${s}_${dt}_${code}`;
|
||||
obj.tmp_sort_2 = `${p}_${s}_${dt}_${code}_${name}`;
|
||||
// Override generic tmp_sort_* with presentation-specific encoding via
|
||||
// build_tmp_sort. Order: priority DESC → sort ASC → start_datetime ASC → code ASC → name ASC
|
||||
const { tmp_sort_1, tmp_sort_2 } = build_tmp_sort({
|
||||
priority: obj.priority,
|
||||
sort: obj.sort,
|
||||
fields_1: [obj.start_datetime, obj.code],
|
||||
fields_2: [obj.name]
|
||||
});
|
||||
obj.tmp_sort_1 = tmp_sort_1;
|
||||
obj.tmp_sort_2 = tmp_sort_2;
|
||||
return obj;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user