Github user nickva commented on a diff in the pull request:
https://github.com/apache/couchdb-couch/pull/239#discussion_r106262038
--- Diff: src/couch_lru.erl ---
@@ -16,48 +16,57 @@
-include_lib("couch/include/couch_db.hrl").
new() ->
- {gb_trees:empty(), dict:new()}.
-
-insert(DbName, {Tree0, Dict0}) ->
- Lru = erlang:now(),
- {gb_trees:insert(Lru, DbName, Tree0), dict:store(DbName, Lru, Dict0)}.
-
-update(DbName, {Tree0, Dict0}) ->
- case dict:find(DbName, Dict0) of
- {ok, Old} ->
- New = erlang:now(),
- Tree = gb_trees:insert(New, DbName, gb_trees:delete(Old, Tree0)),
- Dict = dict:store(DbName, New, Dict0),
- {Tree, Dict};
- error ->
- % We closed this database before processing the update. Ignore
- {Tree0, Dict0}
+ Updates = ets:new(couch_lru_updates, [ordered_set]),
+ Dbs = ets:new(couch_lru_dbs, [set]),
+ {0, Updates, Dbs}.
+
+insert(DbName, {Count, Updates, Dbs}) ->
+ update(DbName, {Count, Updates, Dbs}).
+
+update(DbName, {Count, Updates, Dbs}) ->
+ case ets:lookup(Dbs, DbName) of
+ [] ->
+ true = ets:insert(Updates, {{Count, DbName}}),
--- End diff --
Ha! Caught my trick. To allow iterating easier without doing an extra
lookup in close_int
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---