core: introduce register_dive() function

There was a weird asymmetry, where the undo-commands would
register the fulltext index of the dive, but the core would
unregister the fulltext index in the "unregister_dive()"
function.

To make this more logical, create a "register_dive()" function
in core that does registers the fulltext index.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-06-04 13:52:48 +02:00 committed by bstoeger
parent aa60e5d21d
commit b9df26066e
3 changed files with 21 additions and 12 deletions

View file

@ -72,18 +72,7 @@ dive *DiveListBase::addDive(DiveToAdd &d)
d.site->add_dive(d.dive.get());
diveSiteCountChanged(d.site);
}
dive *res = d.dive.release(); // Give up ownership of dive
// When we add dives, we start in hidden-by-filter status. Once all
// dives have been added, their status will be updated.
res->hidden_by_filter = true;
int idx = dive_table_get_insertion_index(divelog.dives.get(), res);
fulltext_register(res); // Register the dive's fulltext cache
add_to_dive_table(divelog.dives.get(), idx, res); // Return ownership to backend
invalidate_dive_cache(res); // Ensure that dive is written in git_save()
return res;
return register_dive(std::move(d.dive)); // Transfer ownership to core and update fulltext index
}
// Some signals are sent in batches per trip. To avoid writing the same loop

View file

@ -745,6 +745,24 @@ struct dive *unregister_dive(int idx)
return dive;
}
/* Add a dive to the global dive table.
* Index it in the fulltext cache and make sure that it is written
* in git_save().
*/
struct dive *register_dive(std::unique_ptr<dive> d)
{
// When we add dives, we start in hidden-by-filter status. Once all
// dives have been added, their status will be updated.
d->hidden_by_filter = true;
int idx = dive_table_get_insertion_index(divelog.dives.get(), d.get());
fulltext_register(d.get()); // Register the dive's fulltext cache
invalidate_dive_cache(d.get()); // Ensure that dive is written in git_save()
add_to_dive_table(divelog.dives.get(), idx, d.get());
return d.release();
}
void process_loaded_dives()
{
sort_dive_table(divelog.dives.get());

View file

@ -3,6 +3,7 @@
#define DIVELIST_H
#include "units.h"
#include <memory>
#include <vector>
struct dive;
@ -56,6 +57,7 @@ void report_datafile_version(int version);
void clear_dive_file_data();
void clear_dive_table(struct dive_table *table);
struct dive *unregister_dive(int idx);
struct dive *register_dive(std::unique_ptr<dive> d);
extern bool has_dive(unsigned int deviceid, unsigned int diveid);
#endif // DIVELIST_H