Repository navigation
refactor(db): build alias-specific SQL with functions and share the row loop - #432
Merged
Merged
Conversation
…ow loop Build closedTodayUnlogged, upcomingScheduled and somedayDeferred for a given alias instead of string-replacing "t." in their text. Fill the recurrence placeholders through one fillRepeating, write "open or just closed" once as openOrUnlogged, share the title-match decision between GetTask and GetTaskExact, and scan rows through a generic queryAll with a splitTags helper.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Removes duplicated SQL building in
internal/db. This is a refactor: the list-query golden file (testdata/list_query_golden.txt) is unchanged, and so is every other SQL fragment touched here.What changed
closedTodayUnlogged,upcomingScheduledandsomedayDeferredwere turned intop./c.versions bystrings.ReplaceAllon"t."or"t.stopDate". They are now built byclosedUnloggedOf(alias),scheduledLaterOf(alias)anddeferredUndatedOf(alias). Some fragments that depend on them change fromconsttovaras a result.fillRepeating(query, self, parent)fills{{repeating}}and{{repeating_parent}}. It replaces the separateReplaceAllpairs inprobeRepeatingandbuildListQueryand theNewReplacerinListProjects.openOrUnlogged(fold)is used byopenOrJustClosed,ListProjectsandAddTarget.GetTaskandGetTaskExactboth callpickTitleMatch.FindTasksByTitlenow uses the named constantsuntrashedRows,untrashedParentandopenRows, which have the same text.queryAll[T]replaces the query/scan/append loops incollectTasks,ListProjects,ListAreasandListTags.splitTagsreplaces the two\x1fsplits.One clause that is not textually identical
AddTarget's title match wasstatus = ? OR <closedTodayUnlogged>with0bound. It is now(t.status = 0 OR (t.status IN (2, 3) AND <closedTodayUnlogged>)), the same rule the lists andthings projectsuse. The two differ only for a row whose status is not 0, 2 or 3, or is NULL. Things does not write such rows: on the live database every TMTask row has status 0, 2 or 3.Not changed
GetChecklistItemskeeps its own loop. It returns nil when there are no items, andqueryAllreturns an empty slice, so moving it could change JSON output fromnullto[].Checks
make testandmake lintpass. The golden SQL test passes without regenerating.listGrouping,projectPageOrder,projectOfFoldedTagged,parentNotClosedOrUnlogged,heldInPlace,notHeldInPlace,upcomingScope,closedTodayUnloggedand the assembled task query was byte-identical before and after.today,upcoming,anytime,someday,logbook,projects,search,tags,areasandshowwith--jsongave byte-identical output from this branch and from main.