Skip to content

Commit 4d1d169

Browse files
committed
Disentangled Meta_Collector and User:Data_Cache.
1 parent bcbba1e commit 4d1d169

File tree

4 files changed

+43
-56
lines changed

4 files changed

+43
-56
lines changed

src/overpass_api/data/meta_collector.h

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "../../template_db/random_file.h"
2828
#include "../core/settings.h"
2929
#include "../dispatch/resource_manager.h"
30-
#include "user_data_cache.h"
3130

3231

3332
template< typename Index, typename Id_Type >
@@ -47,8 +46,6 @@ struct Meta_Collector
4746
(const Index& index, Id_Type ref);
4847
const OSM_Element_Metadata_Skeleton< Id_Type >* get
4948
(const Index& index, Id_Type ref, uint64 timestamp);
50-
const map< uint32, string >& users() const { return (user_data_cache != 0 ?
51-
user_data_cache->users() : empty_users_); }
5249

5350
~Meta_Collector()
5451
{
@@ -69,7 +66,6 @@ struct Meta_Collector
6966
::Range_Iterator* range_it;
7067
Index* current_index;
7168
set< OSM_Element_Metadata_Skeleton< Id_Type > > current_objects;
72-
User_Data_Cache* user_data_cache;
7369
map< uint32, string > empty_users_;
7470

7571
void update_current_objects(const Index&);
@@ -95,7 +91,7 @@ template< typename Object >
9591
Meta_Collector< Index, Id_Type >::Meta_Collector
9692
(const map< Index, vector< Object > >& items,
9793
Resource_Manager& rman, const File_Properties* meta_file_prop, bool user_data)
98-
: meta_db(0), db_it(0), range_it(0), current_index(0), user_data_cache(0)
94+
: meta_db(0), db_it(0), range_it(0), current_index(0)
9995
{
10096
if (!meta_file_prop)
10197
return;
@@ -105,24 +101,14 @@ Meta_Collector< Index, Id_Type >::Meta_Collector
105101
((rman.get_transaction())->data_index(meta_file_prop));
106102

107103
reset();
108-
109-
if (user_data)
110-
{
111-
if (!rman.user_data_cache())
112-
{
113-
User_Data_Cache* udc = new User_Data_Cache(*rman.get_transaction());
114-
rman.set_user_data_cache(*udc);
115-
}
116-
user_data_cache = rman.user_data_cache();
117-
}
118104
}
119105

120106

121107
template< typename Index, typename Id_Type >
122108
Meta_Collector< Index, Id_Type >::Meta_Collector
123109
(const set< pair< Index, Index > >& used_ranges_,
124110
Resource_Manager& rman, const File_Properties* meta_file_prop)
125-
: used_ranges(used_ranges_), meta_db(0), db_it(0), range_it(0), current_index(0), user_data_cache(0)
111+
: used_ranges(used_ranges_), meta_db(0), db_it(0), range_it(0), current_index(0)
126112
{
127113
if (!meta_file_prop)
128114
return;

src/overpass_api/data/user_data_cache.h

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,30 @@
3131

3232
struct User_Data_Cache
3333
{
34-
public:
35-
User_Data_Cache(Transaction& transaction);
34+
User_Data_Cache() : loaded(false) {}
35+
const std::map< uint32, std::string >& users(Transaction& transaction);
3636

37-
const std::map< uint32, std::string >& users() const { return users_; }
38-
39-
private:
40-
std::map< uint32, std::string > users_;
37+
private:
38+
std::map< uint32, std::string > users_;
39+
bool loaded;
4140
};
4241

43-
inline User_Data_Cache::User_Data_Cache(Transaction& transaction)
42+
43+
inline const std::map< uint32, std::string >& User_Data_Cache::users(
44+
Transaction& transaction)
4445
{
45-
Block_Backend< Uint32_Index, User_Data > user_db
46-
(transaction.data_index(meta_settings().USER_DATA));
47-
for (Block_Backend< Uint32_Index, User_Data >::Flat_Iterator it = user_db.flat_begin();
48-
!(it == user_db.flat_end()); ++it)
49-
users_[it.object().id] = it.object().name;
46+
if (!loaded)
47+
{
48+
Block_Backend< Uint32_Index, User_Data > user_db
49+
(transaction.data_index(meta_settings().USER_DATA));
50+
for (Block_Backend< Uint32_Index, User_Data >::Flat_Iterator it = user_db.flat_begin();
51+
!(it == user_db.flat_end()); ++it)
52+
users_[it.object().id] = it.object().name;
53+
54+
loaded = true;
55+
}
56+
57+
return users_;
5058
}
5159

5260

src/overpass_api/dispatch/resource_manager.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Resource_Manager
4141
Error_Output* error_output_ = 0)
4242
: transaction(&transaction_), error_output(error_output_),
4343
area_transaction(0), area_updater_(0),
44-
watchdog(watchdog_), user_data_cache_(0),
44+
watchdog(watchdog_),
4545
start_time(time(NULL)), last_ping_time(0), last_report_time(0),
4646
max_allowed_time(0), max_allowed_space(0),
4747
desired_timestamp(NOW), diff_from_timestamp(NOW), diff_to_timestamp(NOW) {}
@@ -52,7 +52,7 @@ class Resource_Manager
5252
: transaction(&transaction_), error_output(error_output_),
5353
area_transaction(&area_transaction_),
5454
area_updater_(area_updater__),
55-
watchdog(watchdog_), user_data_cache_(0),
55+
watchdog(watchdog_),
5656
start_time(time(NULL)), last_ping_time(0), last_report_time(0),
5757
max_allowed_time(0), max_allowed_space(0),
5858
desired_timestamp(NOW), diff_from_timestamp(NOW), diff_to_timestamp(NOW) {}
@@ -62,10 +62,6 @@ class Resource_Manager
6262
if (area_updater_)
6363
delete area_updater_;
6464
area_updater_ = 0;
65-
66-
if (user_data_cache_)
67-
delete user_data_cache_;
68-
user_data_cache_ = 0;
6965
}
7066

7167
map< string, Set >& sets()
@@ -103,8 +99,7 @@ class Resource_Manager
10399
void set_diff_from_timestamp(uint64 timestamp) { diff_from_timestamp = timestamp; }
104100
void set_diff_to_timestamp(uint64 timestamp) { diff_to_timestamp = timestamp; }
105101

106-
void set_user_data_cache(User_Data_Cache & user_data_cache) { user_data_cache_ = &user_data_cache; }
107-
User_Data_Cache* user_data_cache() { return user_data_cache_; }
102+
const std::map< uint32, std::string >& users() { return user_data_cache.users(*transaction); }
108103

109104
private:
110105
map< string, Set > sets_;
@@ -116,7 +111,7 @@ class Resource_Manager
116111
Transaction* area_transaction;
117112
Area_Usage_Listener* area_updater_;
118113
Watchdog_Callback* watchdog;
119-
User_Data_Cache* user_data_cache_;
114+
User_Data_Cache user_data_cache;
120115
int start_time;
121116
uint32 last_ping_time;
122117
uint32 last_report_time;

src/overpass_api/statements/print.cc

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,8 @@ void Print_Statement::tags_quadtile
628628
if (++element_count > limit)
629629
return;
630630
print_item(target, item_it->first.val(), *it2, &(tags_by_id[it2->id]),
631-
meta_printer.get(item_it->first, it2->id), &(meta_printer.users()));
631+
meta_printer.get(item_it->first, it2->id),
632+
meta_file_prop ? &(rman.users()) : 0);
632633
}
633634
++item_it;
634635
}
@@ -710,7 +711,7 @@ void Print_Statement::tags_quadtile_attic
710711
meta = current_meta_printer.get(item_it->first, it2->id, it2->timestamp);
711712
print_item(target, item_it->first.val(), *it2,
712713
&(tags_by_id[Attic< typename Object::Id_Type >(it2->id, it2->timestamp)]),
713-
meta, &(current_meta_printer.users()));
714+
meta, &(rman.users()));
714715
}
715716
++item_it;
716717
}
@@ -937,10 +938,12 @@ void Print_Statement::tags_by_id
937938
(items_by_id[i.val()].first->id));
938939
if (++element_count > limit)
939940
return;
940-
print_item(target, items_by_id[i.val()].second, *(items_by_id[i.val()].first),
941-
&(tags_by_id[items_by_id[i.val()].first->id.val()]),
942-
(meta_it != metadata.end() && meta_it->ref == items_by_id[i.val()].first->id) ?
943-
&*meta_it : 0, &(meta_printer.users()));
941+
if (meta_it != metadata.end() && meta_it->ref == items_by_id[i.val()].first->id)
942+
print_item(target, items_by_id[i.val()].second, *(items_by_id[i.val()].first),
943+
&(tags_by_id[items_by_id[i.val()].first->id.val()]), &*meta_it, &(rman.users()));
944+
else
945+
print_item(target, items_by_id[i.val()].second, *(items_by_id[i.val()].first),
946+
&(tags_by_id[items_by_id[i.val()].first->id.val()]), 0, 0);
944947
}
945948
}
946949
}
@@ -1095,7 +1098,7 @@ void Print_Statement::tags_by_id_attic
10951098
print_item(target, items_by_id[i.val()].idx.val(), *items_by_id[i.val()].obj,
10961099
&(current_tags_by_id[items_by_id[i.val()].obj->id.val()]),
10971100
(meta_it != only_current_metadata.end() && meta_it->ref == items_by_id[i.val()].obj->id) ?
1098-
&*meta_it : 0, &(only_current_meta_printer.users()));
1101+
&*meta_it : 0, &(rman.users()));
10991102
}
11001103
else
11011104
{
@@ -1106,7 +1109,7 @@ void Print_Statement::tags_by_id_attic
11061109
Attic< Object >(*items_by_id[i.val()].obj, items_by_id[i.val()].timestamp),
11071110
&(attic_tags_by_id[Attic< typename Object::Id_Type >
11081111
(items_by_id[i.val()].obj->id, items_by_id[i.val()].timestamp)]),
1109-
meta_it != attic_metadata.end() ? &*meta_it : 0, &current_meta_printer.users());
1112+
meta_it != attic_metadata.end() ? &*meta_it : 0, &rman.users());
11101113
}
11111114
}
11121115
}
@@ -2340,9 +2343,6 @@ void Print_Statement::execute(Resource_Manager& rman)
23402343

23412344
if (mode & Print_Target::PRINT_TAGS)
23422345
{
2343-
User_Data_Cache* user_data_cache =
2344-
(collection_mode == collect_rhs ? new User_Data_Cache(*rman.get_transaction()) : 0);
2345-
23462346
if (order == order_by_id)
23472347
{
23482348
if (rman.get_desired_timestamp() == NOW)
@@ -2360,7 +2360,7 @@ void Print_Statement::execute(Resource_Manager& rman)
23602360
element_count);
23612361

23622362
if (collection_mode == collect_rhs)
2363-
collection_print_target->clear_nodes(rman, &user_data_cache->users(), add_deletion_information);
2363+
collection_print_target->clear_nodes(rman, &rman.users(), add_deletion_information);
23642364

23652365
if (rman.get_desired_timestamp() == NOW)
23662366
tags_by_id(mit->second.ways, *osm_base_settings().WAY_TAGS_LOCAL,
@@ -2377,7 +2377,7 @@ void Print_Statement::execute(Resource_Manager& rman)
23772377
element_count);
23782378

23792379
if (collection_mode == collect_rhs)
2380-
collection_print_target->clear_ways(rman, &user_data_cache->users(), add_deletion_information);
2380+
collection_print_target->clear_ways(rman, &rman.users(), add_deletion_information);
23812381

23822382
if (rman.get_desired_timestamp() == NOW)
23832383
tags_by_id(mit->second.relations, *osm_base_settings().RELATION_TAGS_LOCAL,
@@ -2394,7 +2394,7 @@ void Print_Statement::execute(Resource_Manager& rman)
23942394
element_count);
23952395

23962396
if (collection_mode == collect_rhs)
2397-
collection_print_target->clear_relations(rman, &user_data_cache->users(), add_deletion_information);
2397+
collection_print_target->clear_relations(rman, &rman.users(), add_deletion_information);
23982398

23992399
if (rman.get_area_transaction())
24002400
tags_by_id(mit->second.areas, *area_settings().AREA_TAGS_LOCAL,
@@ -2418,7 +2418,7 @@ void Print_Statement::execute(Resource_Manager& rman)
24182418
}
24192419

24202420
if (collection_mode == collect_rhs)
2421-
collection_print_target->clear_nodes(rman, &user_data_cache->users(), add_deletion_information);
2421+
collection_print_target->clear_nodes(rman, &rman.users(), add_deletion_information);
24222422

24232423
tags_quadtile(mit->second.ways, *osm_base_settings().WAY_TAGS_LOCAL,
24242424
*target, rman, *rman.get_transaction(),
@@ -2435,7 +2435,7 @@ void Print_Statement::execute(Resource_Manager& rman)
24352435
}
24362436

24372437
if (collection_mode == collect_rhs)
2438-
collection_print_target->clear_ways(rman, &user_data_cache->users(), add_deletion_information);
2438+
collection_print_target->clear_ways(rman, &rman.users(), add_deletion_information);
24392439

24402440
tags_quadtile(mit->second.relations, *osm_base_settings().RELATION_TAGS_LOCAL,
24412441
*target, rman, *rman.get_transaction(),
@@ -2452,16 +2452,14 @@ void Print_Statement::execute(Resource_Manager& rman)
24522452
}
24532453

24542454
if (collection_mode == collect_rhs)
2455-
collection_print_target->clear_relations(rman, &user_data_cache->users(), add_deletion_information);
2455+
collection_print_target->clear_relations(rman, &rman.users(), add_deletion_information);
24562456

24572457
if (rman.get_area_transaction())
24582458
{
24592459
tags_quadtile(mit->second.areas, *area_settings().AREA_TAGS_LOCAL,
24602460
*target, rman, *rman.get_area_transaction(), 0, element_count);
24612461
}
24622462
}
2463-
2464-
delete user_data_cache;
24652463
}
24662464
else if (mode & Print_Target::PRINT_COUNT)
24672465
{

0 commit comments

Comments
 (0)